說明:本文記錄一些開發中遇到的小技能點,如果你有更好的方法還望不吝賜教。??
UITableView
做為最常用的UI控件,UITableview的人氣那是相當的高啊。想象力沒有天花板的設計大大(maybe產品菊苣)已經玩出了花(bian)樣(tai)。下面來看一下如何滿足他們。
- 和cell等寬的分割線
- iOS7的話,一句搞定(iOS7以上的話只有空cell的分割線才會頂到頭部)
cell.separatorInset = UIEdgeInsetsZero;
//如果全部cell都要這樣 可這樣設置
self.tableView.separatorInset = UIEdgeInsetsZero;//就像tableview的rowHeight一樣 - 哪有只支持iOS7的公司,so
//這兩個屬性均為Available in iOS 8.0 and later
cell.preservesSuperviewLayoutMargins = NO;
cell.layoutMargins = UIEdgeInsetsZero;
- zPosition屬性可以明顯改變屏幕上圖層的順序,但不能改變事件傳遞的順序(摘自iOS核心動畫高級技巧)
GCD
- 創建隊列并設置優先級
dispatch_queue_t serialQueue = dispatch_queue_create("com.mapeng.serialqueue", DISPATCH_QUEUE_SERIAL);
dispatch_set_target_queue(serialQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0));```
#其他
1. UUID能夠唯一標識每一臺設備
- (NSString *)UUID {
KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"HuangyibiaoAppID" accessGroup:@"com.huangyibiao.test.group"];
NSString *UUID = [wrapper objectForKey:(__bridge id)kSecValueData];
if (UUID.length == 0) {
UUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[wrapper setObject:UUID forKey:(__bridge id)kSecValueData];
}
return UUID;
}```
- 如果同時重寫了屬性的getter和setter方法,系統就不會生成對應的ivar。
- 手動創建 ivar
- 使用@synthesize propertyName = _propertyName;
- @import(模塊)
模塊在語義上把框架和import語句封裝到了代碼中,而不是把框架的內容復制粘貼到代碼中。模塊會把H個頭文件預編譯到動態鏈接庫dylib中,并會自動鏈接,這樣就能把編譯時間從O(S*H)降低到O(S+H)。需在Build Setting下打開Enable Modules
NSArray
1.按字母順序排序(Apple's documentation for details)
sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];