【iOS】アプリ系小ネタ4つ+UIColor系小ネタ
続いてアプリ系小ネタいきます!
指定した名前のStoryboardインスタンス取得
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"HogeStoryboard" bundle:nil];
AppDelegate取得
HogeAppDelegate *appDelegate = (HogeAppDelegate *)[UIApplication sharedApplication].delegate;
UUID生成
CFUUIDRef uuidObj = CFUUIDCreate(nil); NSString *uuid = (NSString*)CFBridgingRelease(CFUUIDCreateString(nil, uuidObj)); CFRelease(uuidObj);
アプリショートバージョン取得
Info.plistのBundle versions string, shortを取得しますー
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
【UIColor】#ffffff形式の文字列からUIColor取得
はい、alphaはスルーしてますw
+ (UIColor *)colorWithHexString:(NSString*)string { string = [string stringByReplacingOccurrencesOfString:@"#" withString:@""]; uint32_t hex = 0x0; NSScanner *scanner = [NSScanner scannerWithString:string]; [scanner scanHexInt:&hex]; CGFloat red = ((hex & 0xff0000) >> 16) / 255.0f; CGFloat green = ((hex & 0x00ff00) >> 8) / 255.0f; CGFloat blue = ((hex & 0x0000ff) >> 0) / 255.0f; return [UIColor colorWithRed:red green:green blue:blue alpha:1]; }