简体   繁体   English

UITabbar 背景图像重复本身

[英]UITabbar Background Image Repeats Itself

In my application, i tried to set UITabbar background image as a subview, however, background image gets repeated in UITabbar, below is my code to set the background image in UITabbar在我的应用程序中,我尝试将 UITabbar 背景图像设置为子视图,但是,背景图像在 UITabbar 中重复,下面是我在 UITabbar 中设置背景图像的代码

    tabBar.backgroundImage = UIImage(named: "Pannel.png")
    self.tabBar.isTranslucent = false
    self.tabBar.autoresizesSubviews = false;
    self.tabBar.clipsToBounds = true[![enter image description here][1]][1]

. . Here is my output of tabbar image这是我的标签栏图像的输出

在此处输入图片说明

2nd Approach第二种方法

Add view as SubView将视图添加为子视图

    let bgView: UIImageView = UIImageView(image: UIImage(named: "Pannel.png"))
    bgView.frame = CGRect(x: 0, y: self.tabBar.frame.origin.y - 35, width: self.tabBar.frame.width , height: 64)
    self.view.addSubview(bgView)

Below is my output of 2nd approach以下是我的第二种方法的输出

在此处输入图片说明

Try to resizing the image to tab bar size or you can add an imageView to tab bar as subView, then use image in that imageView.尝试将图像大小调整为标签栏大小,或者您可以将 imageView 作为子视图添加到标签栏,然后在该 imageView 中使用图像。 Just try with below code:只需尝试使用以下代码:

let bgView = UIImageView(image: UIImage(named: "imageName"))
bgView.frame = self.tabBar.bounds
self.tabBar.addSubview(bgView)
self.tabBar.sendSubview(toBack: bgView)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM