[英]Changing tab bar item background color without affecting the tint
我是iOS的新手,我一直陷在设计中。 我搜索了几篇文章,但都没有帮助。
大多数帖子建议用图像替换整个选项卡栏项目,我认为这不是一个好主意。
我希望在情节提要中有类似配置的内容(例如:用户定义的运行时属性),这些配置可以帮助更改项目的背景颜色而不会影响其“色调颜色”。
这是我想要达到的结果。
您可以像这样设置背景图像标签栏,最好通过这种方式自定义标签栏控制器。
在头文件中
#import <UIKit/UIKit.h>
@interface CustomTabBarController : UITabBarController
-(void) setBGView;
@end
在M文件中。
#import "CustomTabBarController.h"
@implementation CustomTabBarController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
-(void)viewDidLoad
{
[super viewDidLoad];
[self setBGView];
}
-(void)setBGView
{
// Background
UIImageView* bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TabBG.png"]] ; //You can create single color image or Single Color view to add
bgView.frame = CGRectMake(0, self.view.frame.size.height-60, elf.view.frame.size.widdth, 60);
[self.view addSubview:bgView];
@end
HTH,享受编码!!
感谢@ViralSavaj和tagyro从这里
我设法实现与我的问题类似的输出,似乎“ setSelectionIndicatorImage”是实现此类输出的唯一方法。
但是,当您在其他设备上运行时,输出效果可能不佳,一种解决此问题的方法是根据设备分辨率绘制形状,您可以从上面的链接中获取代码段
当心您从@tagyro重用的代码
CGSize tabSize = CGSizeMake(CGRectGetWidth(self.view.frame)/5, 49);
您可能要根据选项卡的数量更改/ 5,在我的情况下,我只需要输入4就可以完成工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.