【问题标题】:Customising bookmark icon added to UISearchBar自定义添加到 UISearchBar 的书签图标
【发布时间】:2012-12-22 09:05:25
【问题描述】:

我创建了一个UISearchBar 控件,其书签图标显示在搜索字段本身中。我现在正在尝试寻找方法让我用图像为书签按钮设置皮肤。我偶然发现了this post(请参阅第四条评论),它似乎能够做我想做的事情,但仅适用于搜索字段中的x 按钮,而不适用于书签按钮。

我尝试了以下行来更改按钮,但它似乎不起作用:

[[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundImage:[UIImage imageNamed:@"BookmarkButtonNormal.png"] forState:UIControlStateNormal];
[[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundImage:[UIImage imageNamed:@"BookmarkButtonSelected.png"] forState:UIControlStateSelected];

有人知道我该怎么做吗?

【问题讨论】:

    标签: iphone xcode cocoa-touch ios6 uisearchbar


    【解决方案1】:

    我偶然找到了解决方案。就是这么简单:

    [self.searchBar setImage:[UIImage imageNamed:@"BookmarkButtonNormal.png"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];
    [self.searchBar setImage:[UIImage imageNamed:@"BookmarkButtonSelected.png"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateSelected];
    

    【讨论】:

    • 可能不再起作用。使用 [UISearchBar.appearance setImage:[UIImage imageNamed:@"YourImage"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];
    猜你喜欢
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多