0

my UISegmentedControl in the centre of navbar looks fine in all iOS versions except For IOS 9. I have looked at many discussions but I couldn't find a solution.

This happened at iOS 9 this happened at iOS 9

It should look like this

should look like this

I added the segmented control this way:

listToggle = UISegmentedControl(items: [title1, title2])
self.navigationItem.titleView = listToggle

I also tried to use a UIView to wrap the toggle inside it and then show it, didn't work. making the segmented control smaller does not work neither.

Chris32
  • 4,716
  • 2
  • 18
  • 30

1 Answers1

0

the problem with my UISegmentedControl was that originally I defined some constraints for height and width of the segmentControl. but this approach is wrong when you want to assign a segmented control to titleView on navBar. you should let the titleView itself decide for the height and width of the segmented control.

after all it was working fine on all other iOS versions except for iOS 9 and on a very old device. but it was a good practice to know how title view works.

the other notable thing I learned after this was that you should make sure segmentedControll has a frame before you pass it to titleView and that's all.