gpt4 book ai didi

iphone - 以编程方式设置自定义 UITabBarItem?

转载 作者:行者123 更新时间:2023-12-03 20:35:22 27 4
gpt4 key购买 nike

在 iOS 中,TabBarController 中的 TabBar 属性是只读的。如何将自定义项目与特定 View Controller 关联?如何访问 tabBar 内的 UITabBarItems?

像这样

CustomView *custom = [[CustomView alloc] init];
UITabBarItem *customTab = [[UITabBarItem alloc] initWithTitle:@"Custom" image:[UIImage imageNamed:@"custom.png"] tag:0];
SecondView *second = [[SecondView alloc] init];
UITabBarItem *secondTab = [[UITabBarItem alloc] initWithTitle:@"Next" image:[UIImage imageNamed:@"next.png"] tag:1];
NSArray *views = [NSArray arrayWithObjects:custom,second,nil];
[tabBarController setViewControllers:views];
//how do I set the individual TabBarItems (customTab,secondTab) to be associated
//with the views in question? tabBarController.tabBar is read only

最佳答案

在每个 View Controller 内,您可以设置 tabBarItem 属性。如果 View Controller 由 UITabBarViewController 拥有,则选项卡栏上的关联项目将相应更新。

类似这样的事情

-(void)viewDidLoad {
[super viewDidLoad];
UITabBarItem *tbi = [[UITabBarItem alloc] initWithTitle:yourTitle image:yourIcon tag:yourTag];
[self setTabBarItem:tbi]
[tbi release];
}

显然,您不限于在 viewDidLoad 方法中执行此操作。

关于iphone - 以编程方式设置自定义 UITabBarItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3907926/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com