【问题标题】:Add image on tabbar programmatically in iOS在 iOS 中以编程方式在标签栏上添加图像
【发布时间】:2012-07-09 09:17:55
【问题描述】:

如何在 iOS (Xcode 4.2) 中以编程方式在标签栏上添加图像?

我已经在Could not set tab bar image in Xcode 4.2 Programmatically 提出了问题,但没有得到满意的答复。

【问题讨论】:

    标签: ios objective-c uitabbar


    【解决方案1】:

    iOS 5 外观 api,

    UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
        [[UITabBar appearance] setBackgroundImage:tabBarBackground];
    

    另见thread,投票第二高的答案解释了 5.0 两种情况。

    【讨论】:

      【解决方案2】:

      试试下面的代码

      UITabBarItem *tabItem = [[[UITabBarItem tabBar] items] objectAtIndex:yourIndex];
          [tabItem setTitle:@"theTitle"];
          [tabItem setImage:[UIImage imageNamed:@"yourImage.png"]];
      

      【讨论】:

        【解决方案3】:

        在你的 ViewController 中编写这个方法:

        - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
        {
            self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
            if (self) {
        
                self.tabBarItem.image = [UIImage imageNamed:@"image.png"];
        
            }
            return self;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-07-08
          • 2020-12-24
          相关资源
          最近更新 更多