How can i change the height of UISegmented control. I'm using Swift 3.0 with xcode 8. Height property is disabled by default.
Asked
Active
Viewed 1,617 times
0
-
What hav you tried ? http://stackoverflow.com/questions/12027608/ios-change-the-height-of-uisegmentedcontrol – Umair Afzal Mar 03 '17 at 07:50
-
1Possible duplicate of [iOS: change the height of UISegmentedcontrol](http://stackoverflow.com/questions/12027608/ios-change-the-height-of-uisegmentedcontrol) – kennytm Mar 03 '17 at 07:50
-
I've tried to put autolayout constraint on it but the text then goes upside and do not stays in the middle. @UmairAfzal – Peeyush karnwal Mar 03 '17 at 07:57
-
I've cheched that question but i wanna know if it's possible using Interface builder without any programming bucks. @kennytm – Peeyush karnwal Mar 03 '17 at 07:58
-
@Peeyushkarnwal You should tell us what have you tried with some code or screenshot. – Umair Afzal Mar 03 '17 at 07:59
-
add height constraint for segment control and give constant value as per your requirement. – Prema Janoti Mar 03 '17 at 08:07
-
1This link may help you: http://stackoverflow.com/questions/12027608/ios-change-the-height-of-uisegmentedcontrol/41889155#41889155 – Mar 05 '17 at 14:14
3 Answers
4
I found this:
https://stackoverflow.com/a/41889155/7652057
@IBDesignable class MySegmentedControl: UISegmentedControl {
@IBInspectable var height: CGFloat = 29 {
didSet {
let centerSave = center
frame = CGRect(x: frame.minX, y: frame.minY, width: frame.width, height: height)
center = centerSave
}
}
}
https://stackoverflow.com/a/37716960/7652057
One of three options from the link,
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let rect = CGRect(origin: segment.frame.origin, size: CGSize(width: segment.frame.size.width, height: 100))
segment.frame = rect
}

Community
- 1
- 1
0
Ok, I was trying to do it for a long while and here is the solution. Firstly, It is possible within IB but for that we need to have a good bunch of autolayout constraints.
I've placed that Segmented control in a UIVIew with all the edges pinned inside it. Then I gave the desired height to that view and it worked. Also.. thanks to all of your answer

Peeyush karnwal
- 622
- 7
- 24
-1
It's very easy. You can access it programmaticly by using frame's height:
yourSegmentedControllOutlet.frame.size.height = yourHeight

mcgtrt
- 657
- 6
- 22