0

I want to set the images of tab bar items a bigger size. So I put this code in my TabBarViewController.viewDidLoad():

let titleTabrItems = ["Favourites","Calc","Time","Live","Shop"]
        for (index,item) in (self.tabBar.items ?? []).enumerated() {
            item.title = ""
            let image = item.image?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
            let selectedImage = item.selectedImage?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
            item.image = image
            if index < titleTabrItems.count {
                item.title  = titleTabrItems[index]
            }
            item.titlePositionAdjustment = UIOffsetMake(0, 10000)
            item.selectedImage = selectedImage
            item.imageInsets = UIEdgeInsets(top: 0, left: -10, bottom: -6, right: -10)
        }
        self.navigationController?.setNavigationBarHidden(true, animated: false)

but if I click twice or more times on one item, te image turns bigger and bigger. I guess I still not able to use the EdgeInsets properly. How can I fix the scaling issue and set a bigger size to the images? I created the image files according to Apple documentation (75px/3x, 50px/2x, 25px/1x).

cicaletto79
  • 179
  • 1
  • 12
  • 1
    Possible duplicate of [iOS Tab Bar icons keep getting larger](https://stackoverflow.com/questions/23306963/ios-tab-bar-icons-keep-getting-larger) – Tamás Sengel Jan 12 '18 at 14:31
  • ok thank you @the4kman I solved the issue of increasing size of my tab bar items by updating this line: `item.imageInsets = UIEdgeInsets(top: 6, left: 10, bottom: -6, right: -10)` but now I still need to set a bigger size of them. So how can I do this? – cicaletto79 Jan 12 '18 at 14:40

0 Answers0