Take the 2-minute tour ×

How can I programmtically specify the location of a UISegmentedControl? Setting the frame does nothing. And it seems like mySegmentedControl.frame returns the frame of the buttons and not the "bounding rectangle".

I should note the segmented control I'm working with was added via interface builder.

Edit - more info: so I just learned that segmented controls usually go inside something like a UIToolbar. So I've created an IBOutlet reference to the toolbar created for me by the story board. When I log the location of this toolbar I can see the y-position as off from what I want. However setting the frame of this toolbar doesn't seem to move it.

share|improve this question
have you tried mySegmentedControl.center? Just a guess, are you trying to specify the location of a UISegmentedControl inside a UIBarButtonItem? Make sure your IBOutlet is set correctly and that you are trying to access it after the xib or storyboard has been loaded. –  brynbodayle Oct 23 '12 at 16:06
@bbodayle Thanks for the suggestion. I logged and tried setting the center property. Unfortunately it didn't move the segmented control. It's just dawning on me that segmented controls need to go inside of something else (like a toolbar). Please see additional info in the question. –  SundayMonday Oct 23 '12 at 16:22
Can you post a sample project? –  brynbodayle Oct 23 '12 at 18:30
@bbodayle I resolved the issue by creating the control and wrapping toolbar programmatically. I think this was some bizarre story board/interface builder issue so I don't think I'll post a sample project. Thanks again for your help :-) –  SundayMonday Oct 23 '12 at 19:49
add comment

2 Answers

up vote 2 down vote accepted

Setting the frame is the proper way to do it. There is something else going wrong in your project. You can test this with a simple single view project with a UIButton and a UISegmentedControl:

- (IBAction)buttonTapped:(id)sender {
    self.segmentedControl.frame = ((UIButton*)sender).frame;
    ((UIButton*)sender).hidden = YES;

This will set the segmented control with the same location & size as the button and then hide the button.

share|improve this answer
add comment

Oddly enough, you can’t change just the x or y value, you have to change the whole frame.

I am using synthesized sound in an app and have a delay before the sound plays. If running on less than iOS7 I hide the segmented control and the label. But that leaves a gap in the screen where the control used to be. This code moves the next segmented control up to where the original one was.


            // Hide the delay control
            self.chooseDelaySegmentedControl.hidden = YES;
            self.targetSoundDelayText.text = @"";

            // Move the segmented control up
            CGRect scoringTypeFrame = self.chooseScoringTypeSegmentedControl.frame;
            scoringTypeFrame.origin.y = scoringTypeFrame.origin.y - 70.0f;
            self.chooseScoringTypeSegmentedControl.frame = scoringTypeFrame;

            CGRect scoringTypeTextFrame = self.scoringChoiceText.frame;
            scoringTypeTextFrame.origin.y = scoringTypeTextFrame.origin.y - 70.0f;
            self.scoringChoiceText.frame = scoringTypeTextFrame;

share|improve this answer
add comment

Your Answer


