Change Height of UISegmentedControl

后端 未结 5 1394
小鲜肉
小鲜肉 2021-01-14 09:14

I am trying to change height of UISegmentedControl using this code:

CGRect frame= mySegmentedControl.frame;
[mySegmentedControl setFrame:CGRectM         


        
5条回答
  •  耶瑟儿~
    2021-01-14 10:00

    Perhaps this will help: I had a custom-sized UISegmentedControl within a Storyboard view. The Storyboard views were utilizing AutoLayout and each time I pressed one of the segments, the UISegmentedControl would resize to the default height and not to the custom frame size.

    My solution:

    1) Set the UISegmentedControl frame in -(void)viewDidLoad:

    [mySegControl setFrame:CGRectMake(100, 170, 568, 100)];
    

    2) Set the frame in -(void)viewDidLayoutSubviews:

    [mySegControl setFrame:CGRectMake(100, 170, 568, 100)];
    

    3) In the method you use as the target for when a segment is selected, call setNeedsLayout. This will force the UISegmentedControl to be re-laid-out IAW your custom frame size

    [self.view setNeedsLayout];
    

提交回复
热议问题