朋友您好我在UIPickerview行中显示文字。但是当标签尺寸过大时,Picker行会在标签的末尾显示....
我想在Picker行显示整个标题而不是这个。我可以根据pickerview中的标题宽度自动设置字体大小。
答案 0 :(得分: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 :(得分: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.
}