How to set the text of UISegmentedControl on the left side

I want the text of each segments are aligned to the left, so I tried UIControl contentHorizontalAlignment , but it did not work, so I try to redraw UISegmentedControl , since it will be displayed on the left, but if I choose one segment , the text segment will become a center alignment. Here is my code:

- (void)drawRect:(CGRect)rect {
      NSLog(@"z %s", __FUNCTION__);
      [super drawRect:rect];
      [self changeToLeft];
 }


-(void)changeToLeft
{
  for (UIView *segV in self.subviews) {
    for (UIView *subV in segV.subviews) {
        subV.frameX = 0;
    }
  }
}

      

+3


source to share


2 answers


enter image description here

reduce / change ContentOffset - x

= -somepoints

it automatically appears on the left side



enter image description here

additional link apple doc for segment

+3


source


Check image for steps

When I set an arbitrary content offset in the storyboard and run the app, the text offset remains the same. Check out the video:Video with proof



If your problem remains unresolved, please provide more description. I am more than happy to resolve your request.

+2


source







All Articles