Adjusting the height of the control segment in iPhone

I would like to know if there is a way to change the height of the segment control or maybe change the font size of the control?

Thanks.

+4
source share
8 answers

You can do this only from code, not in InterfaceBuilder. IB tries to stay at Apple HIG , so he does not allow you to change the height.

If you change the height (frame) programmatically, you also need to change the image using setImage: forSegmentAtIndex: as the default image looks terrible when stretched.

+8
source

I know this is old and already answered, but for other searches;

I found that changing the BAR style in attributes in IB is a very quick and acceptable workaround that uses much shorter graphics.

+8
source

When I tried, I could not directly assign the height. I had to do this:

- (void)adjustSegControlHeight:(UISegmentedControl*)segControl :(NSInteger)newHeight { CGRect segControlFrame = segControl.frame; segControlFrame.size.height = newHeight; segControl.frame = segControlFrame; } 

But I decided to use the BAR method.

+1
source

I know this is an older article, but if someone there is still trying to figure it out, I did it. I hope that this will be useful for the needy.

UISegmentedControl *customeSegment = [[UISegmentedControl alloc] initWithFrame:CGRectMake( 206.0f, 7.0f , 110.0f, 30.0f)];

+1
source

Fortunately, you can also change the height and xib.

You can do this with xib . Just add a segment control to xib . Then open xib in TextEdit. There you will find the code

 <segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="B99-Tt-vJG"> <rect key="frame" x="222" y="82" width="123" height="44"/> 

Here you change the height from 44 to any desired height. You can change the height of any UIConponent as follows. Even for UIPickerView .

+1
source

These days there is a way to do this in the interface builder if someone stumbles on this question.

1: click the segmented control in IB 2: on the grid screen, find the โ€œcontactโ€ control in the lower right corner. 3: click "Pin Height" 4: open the size inspector in the utilities area (now you will have a height limit) 5: click the gear and select "Select and Edit"

Pretty hack-y, but if you can't update it by code, this will work.

0
source

How to do this in iOS 7+ using AutoLayout, just add a height limit to the segmented control, and then refresh the frames to solve the auto layout problems. IB will then display the layout at the desired height. You can then edit the height limit to change the height at any time from IB.

0
source

It worked perfect for me. And it has been updated for new versions of iOS and Xcode.

 NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:yoursegmentedControl attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:THE NEW HEIGHT]; [yoursegmentedControl addConstraint:constraint]; 
0
source

Source: https://habr.com/ru/post/1285896/


All Articles