iOS開發(fā)小技巧(持續(xù)更新)

1.切換根視圖控制器淡出的效果(切換成登陸頁面之類的)

self.window.rootViewController = loginVC;

[UIView transitionWithView:self.window

duration:0.5

options:UIViewAnimationOptionTransitionCrossDissolve

animations:^ { self.window.rootViewController = loginVC; }

completion:nil];

2.一個(gè)viewcontroller 包含多個(gè)viewcontroller(可用在切換頁面上)

[self addChildViewController:self.cv1];

[self addChildViewController:self.vc2];

self.currentViewController = self.vc1;

[self.view addSubview:self.vc1.view];

然后在切換的時(shí)候用下面方法

[self transitionFromViewController:self.currentViewController toViewController:self.equipmentListVC duration:0 options:UIViewAnimationOptionTransitionNone animations:^{

} completion:^(BOOL finished) {

[self.view addSubview:self.equipmentListVC.view];

self.currentViewController = self.equipmentListVC;

}];

這個(gè)方法可以用于在給vc瘦身上,分出多個(gè)子視圖控制器,可讀性也會(huì)比較好。

3.圖片不能有alpha 通道

上架App過程中,在上傳預(yù)覽圖、圖標(biāo)的時(shí)候,提示:如果圖片有問題,頁面上會(huì)提示“圖片不能有alpha 通道?!?/p>

解決方案:打開finder,找到圖片,顯示簡介,這里可以看到圖片是否帶有alpha通道;

用mac自帶的預(yù)覽打開圖片,選擇導(dǎo)出,這里可以渲染是否帶alpha通道;

4.在任意頁面讓鍵盤消失掉

[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];

5.數(shù)組內(nèi)查找(數(shù)組包含是字典或?qū)ο蠖伎梢裕?/p>

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", "張三"];

NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];

6.數(shù)組排序

IOS對存放對象的數(shù)組排序

7.快速設(shè)置頁面搭建

使用storyboard的靜態(tài)tableview

8.設(shè)置label的行間距(文字樣式什么的建議用NSMutableAttributedString)

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.contentLabel.text];

NSMutableParagraphStyle *paragraphStyle =? [[NSMutableParagraphStyle alloc] init];? ?

[paragraphStyle setLineSpacing:3];?

? //調(diào)整行間距? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle? ? ? ? ? ? ? ? ? ? ? ? ? range:NSMakeRange(0, [self.contentLabel.text length])];

self.contentLabel.attributedText = attributedString;

9.快速設(shè)置tableview的分割線距離

self.table.separatorInset = UIEdgeInsetsMake(0, 10, 0, 0);

10.去掉多余的分割線

self.table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容