您好,登錄后才能下訂單哦!
小編給大家分享一下iOS導(dǎo)航欄封裝.runtime屬性的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
UIViewController+YINNav
效果
@interface UIViewController (YINNav) /** 控制屏幕方向 在appdelegate 實現(xiàn) - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return [[[NSUserDefaults standardUserDefaults] objectForKey:@"orientation"] integerValue]; } */ @property(nonatomic,assign)UIInterfaceOrientationMask y_screenOrientation; /** 上級控制器 可設(shè)置 手勢返回和pop的時候生效 */ @property (nonatomic) UIViewController *y_popController; /** 是否啟用大標(biāo)題模式 僅支持iOS11 默認(rèn)為NO 。 */ @property(nonatomic,assign)BOOL y_largeTitleMode; /** 隱藏nav橫線 */ @property(nonatomic,assign)BOOL y_navLineHidden; /** nav橫線 */ @property(nonatomic,strong)UIView *y_navLine; /** 字體顏色 默認(rèn)為[UIColor blackColor] */ @property (nonatomic , strong) UIColor *y_navBarTextColor; /** 背景顏色 默認(rèn)為[UIColor whiteColor] */ @property (nonatomic , strong) UIColor *y_navBarBgColor; /** 背景圖 如果設(shè)置了背景圖 背景色無效 */ @property (nonatomic , strong) UIImage *y_navBarBgImg; /** 設(shè)置對應(yīng)的y_navBarAlpha透明度 */ @property (nonatomic , assign) CGFloat y_navBarAlpha; /** navagationbar是否隱藏 默認(rèn)為不隱藏navagationbar */ @property (nonatomic , assign) BOOL y_navBarHidden; @end
看下與系統(tǒng)方法的對比
在我們使用系統(tǒng)api開發(fā)時。常規(guī)的,如果只有其中幾個頁面導(dǎo)航欄樣式不同,局部設(shè)置必須遵循一個原則:"進入頁面時修改,離開頁面時還原”。
比如我們進入一個頁面,需要設(shè)置當(dāng)前導(dǎo)航欄的背景色為灰色,使用如下方法:
//進入頁面時設(shè)置顏色:灰色 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController.navigationBar setBarTintColor:[UIColor grayColor]]; } //離開頁面時還原為全局設(shè)置:橙色 - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.navigationController.navigationBar setBarTintColor:[UIColor orangeColor]]; }
使用UIViewController+YINNav的代碼:
- (void)viewDidLoad { [super viewDidLoad]; self.y_navBarBgColor = [UIColor orangeColor]; }
當(dāng)頁面返回時自動設(shè)置導(dǎo)航欄為即將顯示的controller配置。
透明度漸變效果
- (void)viewDidLoad { [super viewDidLoad]; self.y_navBarAlpha = 0.999;//如果有漸變 不能設(shè)為1 否則會頁面會從導(dǎo)航欄下面開始布局。 self.y_navBarBgColor = [UIColor orangeColor]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ self.y_navBarAlpha = 0.999-(scrollView.contentOffset.y/400.f); }
設(shè)置導(dǎo)航欄背景顏色
- (void)viewDidLoad { [super viewDidLoad]; self.y_navBarBgColor = [UIColor orangeColor]; }
設(shè)置導(dǎo)航欄背景圖
- (void)viewDidLoad { [super viewDidLoad]; //權(quán)重高于背景色 self.y_navBarBgImg = [UIImage imageNamed:@"app2"]; }
設(shè)置導(dǎo)航欄大標(biāo)題
- (void)viewDidLoad { [super viewDidLoad]; self.y_largeTitleMode = YES; }
設(shè)置導(dǎo)航欄隱藏
- (void)viewDidLoad { [super viewDidLoad]; self.y_navBarHidden = YES; }
設(shè)置導(dǎo)航欄細(xì)線
- (void)viewDidLoad { [super viewDidLoad]; self. y_navLineHidden = YES; }
代碼控制返回頁面
- (void)viewDidLoad { [super viewDidLoad]; //傳一個controller對象 可以是navgationcontroller 棧內(nèi)的對象 self.y_popController = [[YINNavAlphaViewController alloc] init]; }
設(shè)置頁面方向
- (void)viewDidLoad { [super viewDidLoad]; self. y_screenOrientation = UIInterfaceOrientationMaskLandscapeRight; }
看完了這篇文章,相信你對“iOS導(dǎo)航欄封裝.runtime屬性的示例分析”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。