Skip to content

Instantly share code, notes, and snippets.

@Huang-Libo
Huang-Libo / YTKAnimatingRequestAccessory.h
Last active June 17, 2016 01:09 — forked from lancy/YTKAnimatingRequestAccessory.h
YTKAnimatingRequestAccessory
//
// YTKAnimatingRequestAccessory.h
// Ape_uni
//
// Created by Chenyu Lan on 10/30/14.
// Copyright (c) 2014 Fenbi. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <YTKBaseRequest.h>
@Huang-Libo
Huang-Libo / gist:20317c86eecde6e492311c0b6adb7803
Created June 16, 2017 08:48 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@Huang-Libo
Huang-Libo / singleton.m
Last active September 7, 2017 09:16
Objective-C singleton
// `dispatch_once' singleton initialisation
+ (id)sharedInstance {
static EOCClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
@Huang-Libo
Huang-Libo / ColorUtils.m
Last active September 27, 2019 09:32
Objective-C 中的颜色工具
/// 参考 WeexSDK `WXConvert.m` 中的 `+UIColor:` 方法 (且在其基础上添加了对 #rrggbbaa 格式的支持)
/// @param colorString 颜色字符串, 支持以下格式:
/// #fff
/// #rrggbb
/// #rrggbbaa
/// rgb(r,g,b)
/// rgba(r,g,b,a)
+ (UIColor *)colorWithColorString:(NSString *)colorString {
// 1. check cache
static NSCache *colorCache;
/// 获取 url 的顶级域名. 比如, a.example.com 的顶级域名是 example.com
- (NSString *)topLevelDomainNameFromUrl:(NSURL *)url {
if (url.absoluteString.length == 0) {
return nil;
}
NSString *topLevelDomainName = @"";
NSString *host = url.host;
NSArray *subStrings = [host componentsSeparatedByString:@"."];
NSUInteger count = subStrings.count;