Two lines of text in a UISegmentedControl

后端 未结 3 1042
日久生厌
日久生厌 2020-12-15 00:34

Try as I might, I can\'t solve a UISegmentedControl bug for an iOS7 iPhone app.

When I create the segmented control, I use this code:

NSArray *segmen         


        
3条回答
  •  生来不讨喜
    2020-12-15 01:06

    And Herzian's solution as a category if anyone wants it. Remember to call it in VWA instead of VDL so it happens after autosizing / rotation

    #import "UISegmentedControl+MultiLine.h"
    
    @implementation UISegmentedControl (MultiLine)
    
    -(void)setupMultiLine
    {
      self.frame = CGRectMake(self.frame.origin.x,
                              self.frame.origin.y,
                              self.frame.size.width,
                              self.frame.size.height*1.6);
      for (id segment in self.subviews)
      {
        for (id label in [segment subviews])
        {
          if ([label isKindOfClass:[UILabel class]])
          {
            UILabel *titleLabel = (UILabel*) label;
            titleLabel.frame = CGRectMake(0,
                                          0,
                                          titleLabel.frame.size.width,
                                          titleLabel.frame.size.height*1.6);
            titleLabel.numberOfLines = 0;
    
          }
        }
      }
    }
    
    @end
    

提交回复
热议问题