- 添加TextFile時(shí),看不到時(shí)記得設(shè)置boardStyle屬性
UITextField *textField = [[UITextField alloc] init];
textField.frame = CGRectMake(50, 40, 120, 40);
//設(shè)置boardStyle屬性
textField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:textField];
當(dāng)兩個(gè)或多個(gè)控制器的View為父子關(guān)系時(shí),那么控制器也一定要為父子關(guān)系
設(shè)置tableView的組與組間的頭部高度和尾部高度,可減小組間的間距
self.tableView.sectionFooterHeight = 10;
self.tableView.sectionHeaderHeight = 10;
tableView的footView的高度問題
tableView的footView只需要設(shè)置高度
自定義tableView的footView時(shí)要記得設(shè)置高度,否則沒法與用戶交互
自定義tableView的footView設(shè)置高度后會(huì)出現(xiàn)下面無(wú)法完全顯示的bug,需要重新給footView高度賦值,或者設(shè)置footView的contentSize
快速獲取沙盒路徑
NSLog(@"%@", NSTemporaryDirectory());
scrollerView自動(dòng)調(diào)整內(nèi)邊距屬性 (導(dǎo)航控制器有導(dǎo)航條會(huì)有64的內(nèi)邊距)
//NO不自動(dòng)調(diào)整內(nèi)邊距
self.automaticallyAdjustsScrollViewInsets = NO;
- layoutIfNeeded setNeedsLayout setNeedsDisplay的使用場(chǎng)景
//重新刷新自己和子控件的所有內(nèi)容
[view layoutIfNeeded];
//重新排布子控件的frame
[view setNeedsLayout];
//重新調(diào)用drawRect方法
[view setNeedsDisplay];
- 簡(jiǎn)單設(shè)置按鈕內(nèi)部文字圖片間距的方式
//contentEdgeInsets:會(huì)影響按鈕內(nèi)部的所有內(nèi)容
button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
//imageEdgeInsets:只影響按鈕內(nèi)部的imageView
button.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
//titleEdgeInsets:只影響按鈕內(nèi)部的titleLable
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
- 實(shí)現(xiàn)tableView組標(biāo)題不懸浮效果
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.tableView)
{
CGFloat sectionHeaderHeight = 25; //sectionHeaderHeight
if (scrollView.contentOffset.y <= sectionHeaderHeight&&scrollView.contentOffset.y >= 0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
}
- 實(shí)現(xiàn)UICollectionView組頭裳仆、尾標(biāo)題懸浮效果
sectionHeadersPinToVisibleBounds
sectionFootersPinToVisibleBounds
使用 NSUserDefaults 存儲(chǔ)自定義對(duì)象:需要將自定義類型轉(zhuǎn)換為NSData類型卿拴,然后將自定義類型數(shù)據(jù)存入 NSUserDefaults 中杆勇。相關(guān)學(xué)習(xí)
在使用tableview的tableHeaderView時(shí),自定義xib時(shí),會(huì)出現(xiàn)位置偏移或者會(huì)蓋住下面的cell或不會(huì)隨著tableview的滾動(dòng)而滾動(dòng)時(shí)等情況,這時(shí)候需要對(duì)tableHeaderView進(jìn)行一下包裝,先在本控制器添加一個(gè)view設(shè)置為tableHeaderView沉填,然后將自定義的xib添加到這個(gè)view上即可
bounds補(bǔ)充:bounds是以自己控件的左上角為原點(diǎn),bounds的大小就是偏移量content offset的值
通過xib創(chuàng)建cell的時(shí)候 xib中在View同一層級(jí)出現(xiàn)了其他的控件
"*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (Cell) - nib must contain exactly one top level object which must be a UITableViewCell instance'"
- 監(jiān)聽textView的return,使其退下鍵盤
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
- 使用xib的IBOutletCollection佑笋,數(shù)組有可能會(huì)無(wú)序翼闹,需要手動(dòng)排序,我是對(duì)每個(gè)控件進(jìn)行設(shè)置tag蒋纬,然后進(jìn)行排序
- (NSArray *)sortedArrayUsingComparator:(NSArray *)array{
return [array sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
if ([obj1 tag]< [obj2 tag]) return NSOrderedAscending;
else if ([obj1 tag] > [obj2 tag]) return NSOrderedDescending;
else return NSOrderedSame;
}];
}
- tableViewCell分隔線
// 添加分隔線
-(void)viewDidLayoutSubviews
{
if ([self.taskDetailTV respondsToSelector:@selector(setSeparatorInset:)]) {
[self.taskDetailTV setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
}
if ([self.taskDetailTV respondsToSelector:@selector(setLayoutMargins:)]) {
[self.taskDetailTV setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
- presentViewController跳轉(zhuǎn)界面有時(shí)會(huì)有卡頓猎荠,需要開個(gè)異步線程
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:nextVC animated:NO completion:^{
}];
});
- 移除所有子試圖
[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- tableview在iPad上顯示不全問題,如下圖:
解決方案:
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0)
{
self.xxxTableView.cellLayoutMarginsFollowReadableWidth = NO;
}
不斷總結(jié)更新蜀备,歡迎補(bǔ)充……