2015-05-04 38 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感謝您的建議。我已經相應地更新了答案。 –