【问题标题】:TabBar / "More View Controller" - Possible to have icons in colors other than black?TabBar /“更多视图控制器” - 可能有黑色以外颜色的图标?
【发布时间】:2010-05-24 12:09:07
【问题描述】:
是否可以让 TabBar 和/或“更多导航控制器”中的图标采用灰色和黑色以外的颜色?我尝试使用 UITabBarItem 更改为视图控制器设置的图标的颜色
- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag
方法。
我的客户认为界面太暗,想用一些彩色图标来点亮它...
谢谢!
【问题讨论】:
标签:
iphone
objective-c
cocoa-touch
uitabbaritem
【解决方案1】:
这有点晚了,但我更改更多控制器图标的方法是(不确定 Apple 是否会批准)执行以下操作:
id moreNavController = [tabs.moreNavigationController.viewControllers objectAtIndex:0];
if ([moreNavController respondsToSelector(@selector(view)]) {
UITableView *t = (UITableView*)[moreNavController view];
[t setDataSource:self];
}
然后我只实现 UITableViewDatasourceProtocol 方法
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
id o =[tabs.moreNavigationController.viewControllers objectAtIndex:0];
return [o tableView:tableView numberOfRowsInSection:section]; //let the existing data source actually return the number of rows
}
和
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
/* configure cell as normal with what ever image in the imageView property*/
cell.imageView.image = <someimageobj>
}
【解决方案2】:
不 :( 标签栏或工具栏上的按钮是使用 Alpha 通道绘制的,因此尽管 .png 有颜色,但它们没有颜色。
因此,您可以继承 TabBar 或 ToolBar 并实现自己的按钮来绘制整个栏。