我正在使用外观API自定义UISearchBar

[[UISearchBar appearance] setSearchFieldBackgroundImage:searchBackground forState:UIControlStateNormal];
[[UISearchBar appearance] setBackgroundImage:backgroundImage];
[[UISearchBar appearance] setScopeBarBackgroundImage:backgroundImage];
[[UISearchBar appearance] setBackgroundColor:[UIColor clearColor]];

我在作为其他类的父类的类中使用此方法,以便在所有类上实现效果。

现在,我需要自定义包含UISearchBar的子类之一。我尝试了link

但是在 super class 上完成外观时,我无法获得那种效果。如果删除外观,则可以实现此效果。

如何通过实现外观 API来做到这一点?

最佳答案

基于Apple's documentation

    [[UISearchBar appearanceWhenContainedIn:[yourSubClassedViewControllerWhichHasSearchbar class], nil]
     setBackgroundColor:[UIColor orangeColor]];

08-04 15:09
查看更多