如何从UIColor常量中获取颜色名称

时间:2012-12-18 07:20:49

标签: ios uicolor

我想在PickerView中显示一些颜色名称,它们是UIColr类的常量

pickerContent = [[NSArray alloc] initWithObjects:[UIColor redColor],[UIColor orangeColor],[UIColor purpleColor],[UIColor yellowColor], nil ];

我为PickerView标签实现的函数是

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
  return [(UIColor *)[self.pickerContent objectAtIndex:row] description];
}

我知道描述不会给我我想要的输出。

所以请帮助您提出宝贵的建议。

1 个答案:

答案 0 :(得分:2)

如果您只想在Picker视图中显示颜色名称,那么请选择另一个NSArray

NSArray *colourArray=[[NSArray alloc] initWithObjects:@"redColor",@"orangeColor",@"purpleColor",@" yellowColor", nil ];

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

{ return [colourArray objectAtIndex:row]; 

}