2015-05-04 64 views
3

我有一个3段UISegmentedControl。英文字符串完全适合,但西班牙语字符串稍长,不。UISegmentedControl和本地化字符串

enter image description here

enter image description here

什么是动态操作字体大小以适应段的大小字符串正确的程序? UILabel有没有类似于minimumFontScale的房产?

+0

[检查这个](http://stackoverflow.com/questions/28028619/is-it-possible-to-create-multi-line-uisegmentedcontrol) –

回答

1

试试这个 您并不需要设置任何最小字体大小。如果需要,它会自动更改字体大小以显示标题。

NSArray *itemArray = [NSArray arrayWithObjects: @"Title1 testing font size", @"Title2", @"Titl3",nil]; 
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; 
    segmentedControl.frame = YOUR_FRAME; 
    [segmentedControl addTarget:self action:@selector(segmentControlClicked:) forControlEvents:UIControlEventValueChanged]; 
    [self.view addSubview:segmentedControl]; 
    for (id segment in [segmentedControl subviews]) 
    { 
     for (id label in [segment subviews]) 
     { 
      if ([label isKindOfClass:[UILabel class]]) 
       [label setAdjustsFontSizeToFitWidth:YES]; 

     }   
    } 
1

试试这个

[_segmentedControl.subviews enumerateObjectsUsingBlock:^(UIView * obj, NSUInteger idx, BOOL *stop) { 
    [obj.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
     if ([obj isKindOfClass:[UILabel class]]) { 
      UILabel *lblCaption = (UILabel *)obj; 
      lblCaption.minimumFontSize=10.0f; 
//OR 
      lblCaption.minimumFontSize = 0.5f; 
     } 
    }];  
}]; 
+0

为iOS6的变化 'minimumFontSize' 至 - > “lblCaption.minimumScaleFactor = .5f” – mtb

+0

@mtb感谢您的建议。我已经相应地更新了答案。 –