【问题标题】:setting image on UITabBar shows an extra line on Image在 UITabBar 上设置图像会在图像上显示额外的一行
【发布时间】:2014-01-03 14:53:57
【问题描述】:

我在我的应用程序中使用了 UITabBarController(适用于 iPhone 5)。当我试图在 TabBAr 上设置图像时,图像显示一条线。看过两个和我类似的问题,但是没看懂解决方法。

这是我添加图像的方式:

UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];

    tabBarView.frame = CGRectMake(0, -15, 320, 64);

    [tabBarController.tabBar addSubview:tabBarView];

我当前图像的尺寸是 320X64 像素。 如何解决这个问题??

【问题讨论】:

  • 你试过tabBarView.contentMode = UIViewContentModeScaleAspectFit;
  • 如果你设置 tabBar 框架的 y 轴 = -15,那么它肯定会滞后于图像总高度的 -15 个像素。所以实际上你正在显示你的图像,但从底部开始的 15Pixel 让你有一种额外的线条感。你能把你的框架设置为 GCRectMake(0,0,320,64)
  • @KumarKl:是的..它不起作用..
  • @BalramTiwari:现在正在从底部剪切图像。我的图像大小存在一些问题。我不确定现在要对大小进行哪些更改。跨度>

标签: ios uitabbarcontroller uitabbar iphone-5


【解决方案1】:

把这个写在 appdelegate.m didfinishLanching 方法中

UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"]
                          resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

[[UITabBar appearance] setBackgroundImage:tabBackground];

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_select_indicator"]];

【讨论】:

    【解决方案2】:

    在 iOS 6 及以上版本中,UITabBar 有一个阴影图像,如果你想禁用它,你可以调用yourTabBar.shadowImage = [UIImage new]

    在你的情况下tabBarController.tabBar.shadowImage = [UIImage new]

    【讨论】:

    • 还有什么建议吗??
    【解决方案3】:

    是的,可以制作精确的尺寸。

    如果您只是在视图中使用UITabBar,请使用此代码:

    类型:1

    UITabBar *tabBar = [[UITabBar alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 60)];
    [self.view addSubview:tabBar];
    
    UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBar.png"]];
    tabBar.backgroundImage = tabBarView.image;
    

    目前我的图像尺寸是 320 x 5

    类型 2:

    如果您使用的是UITabBarController,请像这样使用它

    UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBar.png"]];
    
    UITabBarController *tabController = [[UITabBarController alloc]init];
    tabController.tabBar.backgroundImage = tabBarView.image;
    

    这是两者的屏幕截图。

    【讨论】:

    • 我的图像是蓝色的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多