Change font size of UISegmentedControl

前端 未结 16 1790
死守一世寂寞
死守一世寂寞 2020-11-28 20:54

Can anyone please tell me how can I change the font type and size of UISegmentedControl?

16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 21:21

    You can get at the actual font for the UILabel by recursively examining each of the views starting with the UISegmentedControl. I don't know if this is the best way to do it, but it works.

    @interface tmpSegmentedControlTextViewController : UIViewController {
    }
    
    @property (nonatomic, assign) IBOutlet UISegmentedControl * theControl;
    
    @end
    
    @implementation tmpSegmentedControlTextViewController
    
    @synthesize theControl; // UISegmentedControl
    
    - (void)viewDidLoad {
      [self printControl:[self theControl]];
      [super viewDidLoad];
    }
    
    - (void) printControl:(UIView *) view {
      NSArray * views = [view subviews];
      NSInteger idx,idxMax;
      for (idx = 0, idxMax = views.count; idx < idxMax; idx++) {
        UIView * thisView = [views objectAtIndex:idx];
        UILabel * tmpLabel = (UILabel *) thisView;
        if ([tmpLabel respondsToSelector:@selector(text)]) {
          NSLog(@"TEXT for view %d: %@",idx,tmpLabel.text);
          [tmpLabel setTextColor:[UIColor blackColor]];
        }
    
        if (thisView.subviews.count) {
          NSLog(@"View has subviews");
          [self printControl:thisView];
        }
      }
    }
    
    @end
    

    In the code above I am just setting the text color of the UILabel, but you could grab or set the font property as well I suppose.

提交回复
热议问题