简体   繁体   中英

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

    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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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