Some basic settings of UITabBarController
7069 단어 controller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ViewController *vc1 = [[ViewController alloc] init];
UserGuideViewController *vc2 = [[UserGuideViewController alloc] init];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];
for(int i=0; i<tabBarController.tabBar.items.count; i++) {
UITabBarItem *item = [tabBarController.tabBar.items objectAtIndex:i];
item.title = [NSString stringWithFormat:@" %d",i];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],UITextAttributeTextColor, nil];
[item setTitleTextAttributes:dict forState:UIControlStateNormal];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],
UITextAttributeTextColor,nil];
[item setTitleTextAttributes:dict2 forState:UIControlStateSelected];
}
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Change the background color of the TabBar
method one:
UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
bgView.backgroundColor = [UIColor redColor];
[self.tabBar insertSubview:bgView atIndex:0];
Method Two: CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.tabBar.backgroundImage = image;
Change TabBarItem's (selected/unselected) background image
Method 1, change the global:
UIImage *bgImage = [UIImage imageNamed:@"Image1"];
[[UITabBar appearance] setBackgroundImage:[bgImage resizableImageWithCapInsets:UIEdgeInsetsZero]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"Image2"]];
Method two, change the specific:[self.tabBar setBackgroundImage:[UIImage imageNamed:@"GuideImage1"]];
[self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"GuideImage2"]];
Change TabBarItem's selected and unselected icons
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *carIcon = [UIImage imageNamed:@"CarIcon"];
UIImage *grayCarIcon = [UIImage imageNamed:@"GrayCarIcon"];
ViewController *vc1 = [[ViewController alloc] init];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@" A" image:carIcon tag:0];
item1.selectedImage = grayCarIcon;
vc1.tabBarItem = item1;
UserGuideViewController *vc2 = [[UserGuideViewController alloc] init];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@" B" image:carIcon tag:0];
item2.selectedImage = grayCarIcon;
vc2.tabBarItem = item2;
self.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];
[self setSelectedViewController:vc2];
}
Change text color of TabBarItem
UITabBarItem *item = self.tabBar.items[0];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],UITextAttributeTextColor, nil];
[item setTitleTextAttributes:dict forState:UIControlStateNormal];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],
UITextAttributeTextColor,nil];
[item setTitleTextAttributes:dict2 forState:UIControlStateSelected];
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Processing controlP5로 GUI 컨트롤러Processing에서 ControlP5 라이브러리를 사용하면 쉽게 GUI 컨트롤러를 만들 수 있습니다. 이번 자주 사용하는 슬라이더와 버튼에 대해 적어 둡니다. 향후 늘릴지도, 늘지 않을지도,라고 하는 곳. Pro...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.