iOS開發(fā)中簡單實(shí)用的幾個小技巧
前言
本文記錄了在iOS開發(fā)過程中所遇到的小知識點(diǎn),以及一些技巧,下面話不多說,來看看詳細(xì)的介紹。
技巧1:UIButton圖片與文字默認(rèn)是左右排列,如何實(shí)現(xiàn)右左排列?
解決技巧:
button.transform = CGAffineTransformMakeScale(-1.0, 1.0); button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0); button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
技巧2:設(shè)置導(dǎo)航欄透明,title與BarButtonItem不透明
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.translucent = YES;
技巧3:設(shè)置導(dǎo)航欄無邊框
self.navigationController.navigationBar.shadowImage = [UIImage new];
技巧4: 隨視圖的滾動導(dǎo)航欄隱藏與顯示(一句代碼即可)
self.navigationController.hidesBarsOnSwipe = Yes;
技巧5:簡單好用的獲取當(dāng)前時間戳
//時間戳 time_t now; time(&now); NSLog(@"---%ld",now);
技巧6:只設(shè)置UIView的左上角和右上角的圓角 (四個圓角位置都可以選擇)
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 100)]; blueView.backgroundColor = [UIColor blueColor]; [self.view addSubview: blueView]; /*設(shè)置圓角位置的枚舉參數(shù) UIRectCornerTopLeft = 1 << 0, UIRectCornerTopRight = 1 << 1, UIRectCornerBottomLeft = 1 << 2, UIRectCornerBottomRight = 1 << 3, UIRectCornerAllCorners = ~0UL */ UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:blueView.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(20.0, 20.0)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = blueView.bounds; maskLayer.path = maskPath.CGPath; blueView.layer.mask = maskLayer;
技巧7: 加載UIWebView后禁止用戶復(fù)制剪切
// 控制器實(shí)現(xiàn)此方法 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(copy:) || action == @selector(paste:)|| action == @selector(cut:)) { return NO; } return [super canPerformAction:action withSender:sender]; }
技巧8:跳轉(zhuǎn)控制器隱藏tabbar一個一勞永逸的方法
// 創(chuàng)建一個Nav基類 重寫pushViewController:方法 如下: -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { viewController.hidesBottomBarWhenPushed = YES; [super pushViewController:viewController animated:animated]; }
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的這些小技巧對各位iOS開發(fā)者們能有所幫助,如果有疑問大家可以留言交流。小編還會陸續(xù)更新關(guān)于iOS相關(guān)技巧的文章,請繼續(xù)關(guān)注腳本之家。
相關(guān)文章
Objective-C優(yōu)雅使用KVO觀察屬性值變化
這篇文章主要為大家介紹了Objective-C優(yōu)雅使用KVO觀察屬性值變化示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08iOS利用余弦函數(shù)實(shí)現(xiàn)卡片瀏覽工具
這篇文章主要為大家詳細(xì)介紹了iOS利用余弦函數(shù)實(shí)現(xiàn)卡片瀏覽工具,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-04-04iOS利用NSAttributedString實(shí)現(xiàn)圖文混排效果示例
iOS7以后,因?yàn)門extKit的強(qiáng)大,可以用NSAttributedString很方便的實(shí)現(xiàn)圖文混排(主要是利用了NSTextAttachment),所以下面這篇文章主要給大家介紹了關(guān)于iOS利用NSAttributedString實(shí)現(xiàn)圖文混排效果的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-10-10詳解適配iOS10 的相關(guān)權(quán)限設(shè)置
在最新版本的iOS10系統(tǒng)中,如果你的項(xiàng)目中訪問了隱私數(shù)據(jù),比如:相機(jī)、相冊、錄音、定位、聯(lián)系人等等。涉及到權(quán)限問題,本篇文章主要介紹了適配iOS10 的相關(guān)權(quán)限設(shè)置,有興趣的可以了解一下。2016-12-12IOS 中l(wèi)oadView,viewDidLoad,viewDidUnload詳解及使用
這篇文章主要介紹了IOS 中l(wèi)oadView,viewDidLoad,viewDidUnload詳解及使用的相關(guān)資料,需要的朋友可以參考下2017-02-02解決ios微信下vue項(xiàng)目組件切換并自動播放音頻問題
最近在做一個英語答題項(xiàng)目,項(xiàng)目需求是通過答題取的成績 , 答題的題型是分為,聽音選圖,看圖選詞和填空題.下面小編給大家?guī)砹薸os微信下vue項(xiàng)目組件切換并自動播放音頻的解決方案,需要的朋友參考下吧2018-01-01圖文講解如何解決App的iOS 7頂部狀態(tài)欄適配問題
至今很多iOS App還要照顧到iOS 7進(jìn)行最低的版本適配,而iOS7開始status bar的實(shí)際屏幕占用情況與iOS 6等不盡相同,這里我們就來以圖文講解如何解決App的iOS 7頂部狀態(tài)欄適配問題2016-06-06