Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: change the height of UISegmentedcontrol

I am trying to change the height of UISegmentedcontrol, but it is not allowed in the Interface Builder. Is there any way to change or it is impossible?

Thanks

like image 907
DavidNg Avatar asked Aug 19 '12 15:08

DavidNg


4 Answers

Adding a constraint in IB will also do the trick:

Constraint in IB

like image 188
Ji Fang Avatar answered Nov 01 '22 04:11

Ji Fang


Yes, you can use [mySegmentedControl setFrame:frame] in code. It is unfortunate that you can't do this in IB.

So, if you just want to change the height:

CGRect frame= mySegmentedControl.frame;
[mySegmentedControl setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, fNewHeight)];
like image 20
Luke Avatar answered Nov 01 '22 03:11

Luke


Add a new height constraint and set its value.

enter image description here

like image 27
naveed148 Avatar answered Nov 01 '22 05:11

naveed148


If you are using Auto Layout and are having trouble with Luke's answer, this worked perfectly for me:

NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:mySegmentedControl
                                     attribute:NSLayoutAttributeHeight 
                                     relatedBy:NSLayoutRelationEqual
                                     toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                     multiplier:1 
                                     constant:fNewHeight];
[mySegmentedControl addConstraint:constraint];
like image 12
jburns20 Avatar answered Nov 01 '22 04:11

jburns20