你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> UITabBar,UITabBarItem怎麼用字典設置UITabBarItem字體大小和顏色,保持原圖顏色

UITabBar,UITabBarItem怎麼用字典設置UITabBarItem字體大小和顏色,保持原圖顏色

編輯:關於IOS

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

// 設置屏幕背景色

self.view.backgroundColor = [UIColor lightTextColor];

 

// 初始化UITabBar

UITabBar * tabBar = [[UITabBar alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 49,self.view.frame.size.width, 49)];

 

// 初始化barItem

UIImage * imgForItem1 = [UIImage imageNamed:@"icon_cinema"];

UIImage * imgForItem2 = [[UIImageimageNamed:@"icon_cinema@2x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

 

UITabBarItem * item1 = [[UITabBarItem alloc]initWithTitle:@"Cinema" image:imgForItem1selectedImage:imgForItem2];

 

UITabBarItem * item2 = [[UITabBarItem alloc]initWithTitle:@"2" image:[UIImageimageNamed:@"more_select_setting"] tag:101];

 

UITabBarItem * item3 = [[UITabBarItem alloc]initWithTitle:@"3" image:[UIImage imageNamed:@"movie_cinema"]tag:102];

 

UITabBarItem * item4 = [[UITabBarItem alloc]initWithTitle:@"Movie" image:[UIImage imageNamed:@"msg_new"]tag:103];

UIImage * img1ForItem5 = [UIImage imageNamed:@"start_top250"];

UIImage * img2ForItem5 = [[UIImageimageNamed:@"start_top250"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

 

 

 

UITabBarItem * item5 = [[UITabBarItem alloc]initWithTitle:@"9" image:img1ForItem5selectedImage:img2ForItem5];

//    NSBackgroundColorAttributeName

// 用字典設置item5的字體顏色

NSDictionary * dict = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor yellowColor]};

// 設置高亮狀態的字體及顏色

[item5 setTitleTextAttributes:dict forState:UIControlStateHighlighted];

 

 

NSArray * array = @[item1,item2,item3,item4,item5];

 

 

tabBar.items = array;

 

[self.view addSubview:tabBar];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved