Sea*_*ean 8 iphone cocoa-touch
有谁知道如何从iPhone SDK更改UIPickerView控件中行(或行背景)的颜色?类似下面的行标题,但我也想改变行的颜色:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
Run Code Online (Sandbox Code Playgroud)
谢谢.
Sea*_*ean 14
谢谢诺亚,这正是我所需要的.我想在这里添加代码以防万一其他人需要(或想要评论:)
- (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;
}
Run Code Online (Sandbox Code Playgroud)