有谁知道如何从iPhone SDK更改UIPickerView控件中行(或行背景)的颜色?类似下面的行标题,但我也想改变行的颜色:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
谢谢.
谢谢诺亚,这正是我所需要的.我想在这里添加代码以防万一其他人需要(或想要评论:)
- (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; }
您可以在委托的-pickerView:viewForRow:forComponent:reusingView:方法中返回任意视图,此处记录.