在uipickerview中选择时如何更改文本颜色? [英] How to change text color when selected in uipickerview?

查看:28
本文介绍了在uipickerview中选择时如何更改文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 uipickerview 选择所在的行的颜色.还有另一个类似的问题,但唯一的答案是显示如何将 uipickerview 中的所有文本更改为某种颜色.我只希望在查看器中选择文本时显示不同的颜色.

I want to change the color of the row that the selection of the uipickerview lands on. There is another question like this but the only answer is showing how to make all the text in the uipickerview changed to a certain color. I just want the text when selected in the viewer to appear a different color.

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger) component reusingView:(UIView *)view
{
    NSString *rowItem =[thing objectAtIndex:row];
    UILabel *lblRow = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView bounds].size.width, 44.0f];
    [lblRow setTextColor: [UIColor grayColor]];
    [lblRow setTextAlignment:NSTextAlignmentCenter];
    [lblRow setText:rowItem];

    [lblRow setBackgroundColor:[UIColor clearColor];

    return lblRow;

}

推荐答案

如何改用这个委托方法:

How about using this delegate method instead:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSString *rowItem =[thing objectAtIndex:row];
    UILabel *lblRow = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView bounds].size.width, 44.0f];
    [lblRow setTextColor: [UIColor grayColor]];
    [lblRow setTextAlignment:NSTextAlignmentCenter];
    [lblRow setText:rowItem];

    [lblRow setBackgroundColor:[UIColor clearColor];
}

这篇关于在uipickerview中选择时如何更改文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆