【问题标题】:Set font as per width根据宽度设置字体
【发布时间】:2013-09-02 17:26:00
【问题描述】:

你好朋友我正在 UIPickerview 行中显示文本。但是当标签尺寸太大时,Picker 行会在标签末尾显示 ...。

我想在 Picker 行中显示整个标题,而不是这个。我可以根据pickerview中的标题宽度自动设置字体大小吗?

【问题讨论】:

标签: iphone ios uipickerview


【解决方案1】:

您需要实现以下方法:

- (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;
}

【讨论】:

    【解决方案2】:

    使您的控制器成为 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.
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 2011-09-03
      • 2015-02-14
      • 2015-05-21
      • 2015-08-27
      • 2015-04-29
      • 1970-01-01
      相关资源
      最近更新 更多