开发者

UIPickerView Font

Does开发者_JAVA技巧 anyone know if it is possible to change the font and/or color for individual UIPickerView Items?


- (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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜