標籤:導航 5.0 ssh stat art ora tintcolor style ons
一、導覽列的背景和文字Color:
方法一:
- //設定NavigationBar 背景顏色&title 顏色
- [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
- [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
方法二:
- //設定NavigationBar背景顏色
- [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
- //@{}代表Dictionary
- [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
二、導覽列使用背景圖片:
1. [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
三、導覽列標題的字型:
UITextAttributeFont - 字型
UITextAttributeTextColor - 文字顏色
UITextAttributeTextShadowColor - 文字陰影顏色
UITextAttributeTextShadowOffset - 位移用於文本陰影
- NSShadow *shadow = [[NSShadow alloc] init];
- shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
- shadow.shadowOffset = CGSizeMake(0, 1);
- [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
- shadow, NSShadowAttributeName,
- [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil nil]];
四、圖片作為導覽列標題:
- self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appcoda-logo.png"]];
五、添加多個欄按鈕項目:
- UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action: nil nil];
- UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action: nil nil];
- NSArray *itemsArr = @[shareItem,cameraItem];
- self.navigationItem.rightBarButtonItems = itemsArr;
六、自訂後退按鈕的文字和顏色:
方法一:
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
- self.navigationItem.backBarButtonItem = item;
- [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];
-
- self.title=[NSString stringWithFormat:@"第%lu頁",(unsigned long)self.navigationController.viewControllers.count];
-
- //自訂返回按鈕
- UIImage *backButtonImage = [[UIImage imageNamed:@"fanhui.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
- [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
- //將返回按鈕的文字position設定不在螢幕上顯示
- [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
自訂iOS導覽列背景,標題和返回按鈕文字顏色