2013-08-30 68 views
2

你好朋友我在UIPickerview行中顯示文本。但是當標籤尺寸太大時,Picker行會在標籤的末尾顯示...。根據寬度設置字體

我想在Picker的行中顯示整個標題而不是這個。我可以根據pickerview中的標題寬度自動設置字體大小。

+0

我沒有清楚ida關於此, 但一旦通過此鏈接, http://stackoverflow.com/questions/5038891/center-uipickerview-text – Friend

回答

2

您需要實現以下方法:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ 

    UILabel* tView = (UILabel*)view; 

    if (!tView){ 

     tView = [[UILabel alloc] init]; 

     // Setup label properties - frame, font, colors etc 
     ... 
    } 

    // Fill the label text here 
    ... 
    return tView; 
} 
1

讓你的控制器UIPickerViewDelegate和UIPickerViewDataSource,那麼你可以使用這個程序,讓你想要的任何自定義更改爲您的機行:

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ 

//make your own view here, it can be a UILabel if you want, or other kind of view. 

//You can give it any size font you need. 

} 
相關問題