当前位置:  开发笔记 > IOS > 正文

UIPickerView行颜色

如何解决《UIPickerView行颜色》经验,为你挑选了2个好方法。

有谁知道如何从iPhone SDK更改UIPickerView控件中行(或行背景)的颜色?类似下面的行标题,但我也想改变行的颜色:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

谢谢.



1> Sean..:

谢谢诺亚,这正是我所需要的.我想在这里添加代码以防万一其他人需要(或想要评论:)

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

    CGRect imageFrame = CGRectMake(0.0, 0.0, 15, 15);
    UIImageView *label = [[[UIImageView alloc] initWithFrame:imageFrame] **autorelease**];

    if (row == 0)
    {
        label.backgroundColor = [UIColor redColor];
    }
    if (row == 1)
    {
        label.backgroundColor = [UIColor blueColor];
    }
    if (row == 2)
    {
        label.backgroundColor = [UIColor blackColor];
    }   
    return label;
}



2> Noah Withers..:

您可以在委托的-pickerView:viewForRow:forComponent:reusingView:方法中返回任意视图,此处记录.

推荐阅读
喜生-Da
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有