ios - 如何在 Objective-C 中更改标签栏的背景图像?

标签 ios objective-c tabbar

我正在开发objective-C。我想改变标签栏背景,如下图:
enter image description here
代码如下:

UIImage *tabBarBackground = [UIImage imageNamed:@"tabbaritem_background.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
但是设置背景图片后,背景不在正确的位置,如下所示:
enter image description here
背景图像应该像上图的背景一样放在底部。
我错过了什么吗?有人能帮我吗 ?
提前致谢。

最佳答案

我认为是您出错的地方,请检查是否是以下步骤:

  • 在 Storyboard 中更改 ViewController 的背景颜色以进行测试。

  • enter image description here
  • 将 ViewController 嵌入标签栏 Controller

  • enter image description here
  • ViewController.m您可以设置标签栏免费颜色:
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        [[UITabBar appearance] setBackgroundColor:[UIColor grayColor]]; // Here you can set the converted color form image, make sure the imageSize fit.
    }
    
  • 结果如下:

  • 关于ios - 如何在 Objective-C 中更改标签栏的背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42287662/

    相关文章:

    ios - TableView 滚动错误

    ios - 构建 react native 应用程序时 : undefined symbols for architecture gxx_personality_v0

    ios - 图像在运行时自动调整大小但不在 Interface Builder 上

    在 Objective-C 中检查对象的大小

    swift - SwiftUI 中堆栈隐藏在选项卡栏后面

    ios - UITableView 不在 becomeFirstResponder 上滚动

    iphone - 重复使用通配符 appId 来启用推送通知

    ios - Apple Mach - O 链接器错误。没有这样的文件或目录 Swifty Json

    ios - 单击其他选项卡栏项目时,自定义选项卡栏会调整大小

    切换选项卡 View 后快速 ScrollView 标签移动