简体   繁体   English

UIPickerView字体

[英]UIPickerView Font

有谁知道是否可以更改单个UIPickerView项目的字体和/或颜色?

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

Yes, it is possible. 对的,这是可能的。 To do that you need to implement pickerView:viewForRow:forComponent:reusingView: method in picker's delegate - create UILabel instance there and setup it with whatever attributes you want. 为此,您需要在选择器的委托中实现pickerView:viewForRow:forComponent:reusingView:方法-在pickerView:viewForRow:forComponent:reusingView:创建UILabel实例,并使用所需的任何属性对其进行设置。

For this, I would simply go with attributed strings. 为此,我将只使用属性字符串。

Implement this method is your delegate: 实现此方法是您的委托:

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView
             attributedTitleForRow:(NSInteger)row
                      forComponent:(NSInteger)component

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM