UIPickerView 怎么去更改选中 item 的字体颜色,在线等。。求助 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wisdominessence
V2EX    macOS

UIPickerView 怎么去更改选中 item 的字体颜色,在线等。。求助

  •  
  •   wisdominessence 2014-12-30 10:56:30 +08:00 9350 次点击
    这是一个创建于 3940 天前的主题,其中的信息可能已经有所发展或是发生改变。

    试了一下不行
    这个也不行

    能否在 didSelectRow 中修改 选中 item 的字体颜色。

    4 条回复    2014-12-30 15:54:37 +08:00
    icestraw
        1
    icestraw  
       2014-12-30 11:40:52 +08:00
    新建一个 property rowA来保存当前选定的行号,一个property listArray用来保存每一行的View, property array保存数据
    然后另外实现这两个方法

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    {
    UILabel *lbl = [UILabel new];
    NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc] initWithString:[_array objectAtIndex:row]];
    NSRange range = NSRangeFromString([_array objectAtIndex:row]);
    [aStr addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor redColor].CGColor range:range];
    lbl.attributedText = aStr;
    if (row == _rowA) {
    lbl.textColor = [UIColor redColor];
    }
    [_listArray addObject:lbl];
    return lbl;
    }


    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
    _rowA = row;
    [_testPicker reloadAllComponents];
    }
    希望有所帮助
    icestraw
        2
    icestraw  
       2014-12-30 11:41:56 +08:00
    @icestraw Oh,在这里Attributed String可以不用>_<
    wisdominessence
        3
    wisdominessence  
    OP
       2014-12-30 13:49:13 +08:00
    @icestraw 能加我QQ 嘛,我把代码发你看看 叁9柒壹45215, 可以有偿咨询。
    smartv
        4
    smartv  
       2014-12-30 15:54:37 +08:00
    @icestraw 已解决。感谢回答
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1339 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 17:07 PVG 01:07 LAX 10:07 JFK 13:07
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86