How to set tab bar item title programmatically in objective c?

前端 未结 10 1369
猫巷女王i
猫巷女王i 2021-01-31 15:46

I want to set title to tab item programatically, but it not works. My code is below:

- (IBAction)tab1Click:(id)sender {
    myTabBarController = [[UITabBarContro         


        
10条回答
  •  礼貌的吻别
    2021-01-31 16:14

    The title displayed on a given tab bar item is determined by the corresponding view controller's instance of UITabBarItem. Those aren't mutable, though... if you want to change the title (or image, or tag), you have to make a new item and assign it to the view controller.

    UITabBarItem *item2 = [[UITabBarItem alloc initWithTitle:@"someTitle" image:someImage tag:0];
    viewController2.tabBarItem = item2;
    

提交回复
热议问题