Darshan
Darshan

Reputation: 2379

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

enter image description here

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

enter image description here

Upvotes: 4

Views: 1908

Answers (1)

Kishan Bhatiya
Kishan Bhatiya

Reputation: 2368

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)

Upvotes: 4

Related Questions