iOS开发

关于iOS13 UITextField 通过KVC改变 plac

2020-03-06  本文已影响0人  BlackStar暗星

iOS13不再允许UITextField的placeholder属性通过 kvc 的方式更改颜色和字体等属性,替换方法为:

    UITextField * searchField = self.searchTextField;
    NSString *placeHolder = @"请输入关键词搜索";
    NSMutableAttributedString *placeHolderStr = [[NSMutableAttributedString alloc]initWithString:placeHolder];

    NSDictionary *attrDic = @{@"NSFontAttributeName":[UIFont systemFontOfSize:15],
                              @"NSForegroundColorAttributeName":[UIColor grayColor]};

    [placeHolderStr addAttributes:attrDic} range:NSMakeRange(0, placeHolder.length)];
    searchField.attributedPlaceholder = placeHolderStr;
上一篇 下一篇

猜你喜欢

热点阅读