2

I implemented tab bar with custom icon size.i find many solution from stack-overflow but i didn't getting any perfect solution for this issue.

Issue : when i click tabbar item again and again it's size double every time. and after click other tab it's size is same as orignal size.

See this Link For Issue : Screen Recording

My Code :

import UIKit

class customTabBar: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()

    let tabHome2 = self.tabBar.items![2]
    tabHome2.image = UIImage(named: "ic_pick")?.withRenderingMode(.alwaysOriginal)
    tabHome2.selectedImage = UIImage(named: "ic_pick")?.withRenderingMode(.alwaysOriginal) 
    tabHome2.imageInsets = UIEdgeInsets(top: -40, left: -10, bottom: 0, right: -10)

}

}

My Design Requirement :

enter image description here

Thanks In Advance.

Panda
  • 6,955
  • 6
  • 40
  • 55
Dixit Akabari
  • 2,419
  • 13
  • 26
  • What does your code show? You say the problem is while tapping on the image, so share that code. – Yevgeniy Leychenko Dec 05 '18 at 06:40
  • @Evgeniy not any code in tapping i just set above code and i click again and again in selected tab at that time i getting this issue.please see screen recording url i put in my question. – Dixit Akabari Dec 05 '18 at 06:42
  • We need to see the method that is called when the button is tapped. You said it's occurring when the button is tapped; where is the code? Do you have any implementation for when tapping a tab bar item? – Hedylove Dec 05 '18 at 07:06
  • @JozemiteApps i did't any implementation on tapping a tab bar item.see my update question with UITabBarController full code. – Dixit Akabari Dec 05 '18 at 07:10
  • Are you using a library to show that button in the middle? That is the one with the issue, right? – Hedylove Dec 05 '18 at 07:11
  • 1
    @JozemiteApps no i didn't use any library. tabHome2.imageInsets = UIEdgeInsets(top: -40, left: -10, bottom: 0, right: -10) this code for middle button. – Dixit Akabari Dec 05 '18 at 07:12
  • What happens if you take off the rendering mode methods? Since if you have the image at the right size, are these necessary? – Hedylove Dec 05 '18 at 07:16
  • @JozemiteApps Please see ScreenRecording in question. first time tab bar same as my requirement but when i click multiple time on middle button at that time this image zoom(double) automatically. – Dixit Akabari Dec 05 '18 at 07:19

2 Answers2

1

Set Icons in assets. If you are using circular icons for tab bar item you should create following sizes for portrait mode:

  • @1x : about 25 x 25 (max: 48 x 32)

  • @2x : about 50 x 50 (max: 96 x 64)

  • @3x : about 75 x 75 (max: 144 x 96)

Also you can refer this : custom-icons

Set image inset from the property of Tabbar item. Image

B K.
  • 534
  • 5
  • 18
  • This is irrelevant as they said the size doubles every time they tap it. And it goes back to normal size when tapping another tab bar item. – Hedylove Dec 05 '18 at 07:12
0

Your image insets are not balanced. Try:

tabHome2.imageInsets = UIEdgeInsets(top: -20, left: -10, bottom: 20, right: 10)

  • Try to reproduce bug.
  • Bug is gone.
  • Find the right values. (Image edit might be needed.)
  • Open a beer.