开发者

UIPickerView Font

开发者 https://www.devze.com 2023-02-21 02:57 出处:网络
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 forCompo

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

精彩评论

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