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

  // 方法一(推荐使用)

    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的占位文字颜色)