在pickerview中更改字体颜色

时间:2013-05-19 01:33:26

标签: objective-c uipickerview

我需要在我的选择器视图中更改一行中的字体颜色,让我们说它是我的乌鸦图像,我该怎么做。
这就是我到目前为止所做的 我搜索过,但我在这里找不到答案。 当我启动它时,我可以在我的选择器视图应用程序中获得启动画面。

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Load up NSArray object
_fuglar = [[NSArray alloc]initWithObjects:@"Allt árið", @"Hrafn", @"Svartbakur",@"Silfurmáfur",@"Sílamáfur",@"Frá 20.ágúst til 15.mars",@"Grágæs",@"Heiðagæs",@"Frá 1.september til 15.mars",@"Fýll",@"Dílaskarfur",@"Toppskarfur",@"Helsingi",@"Stokkönd", @"Urtönd",@"Rauðhöfðaönd",@"Duggönd",@"Skúfönd",@"Hávella",@"Toppönd",@"Hvítmáfur",@"Hettumáfur",@"Rita",@"Álka",@"Langvía",@"Stuttnefja",@"Teista",@"Lundi",@"Rjúpa", nil];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - UIPickerView Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:      (NSInteger)component
{
return _fuglar.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [_fuglar objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
 //Create UIImage objects
UIImage * uglaImage = [UIImage imageNamed:@"ugla1.jpg"];
UIImage * ravenImage = [UIImage imageNamed:@"raven.jpg"];
UIImage * svartbakurImage = [UIImage imageNamed:@"svartbakur2.jpg"];
UIImage * silfurmafurImage = [UIImage imageNamed:@"silfurmafur.jpg"];


switch (row) {
    case 0:
        fuglarImage.image = uglaImage;
        break;
    case 1:
        fuglarImage.image = ravenImage;
        break;
    case 2:
        fuglarImage.image = svartbakurImage;
        break;

1 个答案:

答案 0 :(得分:0)

您需要实施pickerView:viewForRow:forComponent:reusingView:而不是pickerView:titleForRow:forComponent:

您的实现应返回UILabel,其中包含您需要的任何属性。