/*
设置uitabr 样式
此方法需要设置了viewControllers 后设置了后调用
tabBar.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nil];
*/
-(void) setUITabBarStyle :(UITabBarController *)tabBar
{
for(UIView *view in tabBar.tabBar.subviews)
{
if([view isKindOfClass:[UIImageView class]])
{
[view removeFromSuperview];
}
}
UIImageView *imageView = [[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"teb.png"]]autorelease];
imageView.width = tabBar.tabBar.width;
imageView.height = tabBar.tabBar.height;
[tabBar.tabBar insertSubview:imageView atIndex:0];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5"))
{
[tabBar.tabBar setSelectedImageTintColor:[UIColor whiteColor]];
UIImage *img = [UIImage imageNamed:@"tab_bg.png"];
UIImage *img1 = [img imageByScalingToSize:CGSizeMake(imageView.width/[[tabBar viewControllers]count],imageView.height)];
[tabBar.tabBar setSelectionIndicatorImage:img1];
}
}
本文介绍了一种定制UITabBarController中TabBar样式的Objective-C方法。通过移除默认背景并添加自定义图片作为背景,同时调整选中状态的颜色及指示器图片。适用于iOS 5及以上版本。
81

被折叠的 条评论
为什么被折叠?



