我目前正在使用Xcode 5来开发面向列表的应用程序.我有标签栏的自定义色调,标签图标的自定义图像,选中标签栏的图标图像的自定义色调,但我找不到如何自定义图标图像的未选中时的色调.现在它只是默认的灰色,与我的绿色标签栏相比,你几乎看不到它.我想将标签栏图标的图像和名称设为白色.
有人知道如何在Xcode 5中设置标签栏图标的图像色调吗?
Mat*_*rke 26
您需要为每个选项卡(未选中)图像设置渲染模式UIImageRenderingModeAlwaysOriginal.因此,在您的app委托中,获取对标签栏的引用,然后遍历每个标签栏项,调整图像模式.
可能有更好的方法来获得对标签栏的引用,但我做了以下事情:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tbc = [sb instantiateInitialViewController];
self.window.rootViewController = tbc;
UITabBar *tb = tbc.tabBar;
Run Code Online (Sandbox Code Playgroud)
然后可以按如下方式进行图像调整:
NSArray *items = tb.items;
for (UITabBarItem *tbi in items) {
UIImage *image = tbi.image;
tbi.selectedImage = image;
tbi.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
Run Code Online (Sandbox Code Playgroud)
Jor*_*tel 17
你可以试试这个色调选中的图标:
// Custom the tab bar
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
这是为非活动图标着色:
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"item_seleted.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"item_unselected.png"]];
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以通过添加"用户定义的运行时属性"来完全从故事板中执行此操作而无需编写任何代码:
试试这种方式..这对我有用
在app delegate中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UITabBarController *tabBarController=(UITabBarController*)(self.window.rootViewController);
UITabBar *tabBar=tabBarController.tabBar;
UITabBarItem *tabBarItem1=[[tabBar items] objectAtIndex:0];//first tab bar
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"yourImageSelected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"yourImageUnselected.png"]];//image should be 30 by 30
}
Run Code Online (Sandbox Code Playgroud)
跑去吧
| 归档时间: |
|
| 查看次数: |
30867 次 |
| 最近记录: |