美文网首页
(IOS)修改UISearchBar的占位文字颜色

(IOS)修改UISearchBar的占位文字颜色

作者: rightmost | 来源:发表于2018-08-10 17:35 被阅读0次

  // 方法一(推荐使用)

    UITextField*searchField = [searchBarvalueForKey:@"_searchField"];

    [searchFieldsetValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];

    // 方法二(已过期)

    [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor]];

    // 方法三(已过期)

    NSDictionary *placeholderAttributes = @{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:15],};

    NSAttributedString*attributedPlaceholder = [[NSAttributedString alloc] initWithString:searchBar.placeholder attributes:placeholderAttributes];

    [[UITextField appearanceWhenContainedIn:[UISearchBar class],nil] setAttributedPlaceholder:attributedPlaceholder];

相关文章

网友评论

      本文标题:(IOS)修改UISearchBar的占位文字颜色

      本文链接:https://www.haomeiwen.com/subject/yxslbftx.html