Ios 目标C-改变控制外观,实施外观api
我正在使用外观api定制Ios 目标C-改变控制外观,实施外观api,ios,objective-c,uisearchbar,uiappearance,Ios,Objective C,Uisearchbar,Uiappearance,我正在使用外观api定制UISearchBar [[UISearchBar appearance] setSearchFieldBackgroundImage:searchBackground forState:UIControlStateNormal]; [[UISearchBar appearance] setBackgroundImage:backgroundImage]; [[UISearchBar appearance] setScopeBarBackgroundImage:backg
UISearchBar
[[UISearchBar appearance] setSearchFieldBackgroundImage:searchBackground forState:UIControlStateNormal];
[[UISearchBar appearance] setBackgroundImage:backgroundImage];
[[UISearchBar appearance] setScopeBarBackgroundImage:backgroundImage];
[[UISearchBar appearance] setBackgroundColor:[UIColor clearColor]];
我在其他类的父类中使用它,以便在所有子类上实现该效果
现在我需要自定义包含UISearchBar
的子类之一。我试过了
但是当在超类上进行外观时,我无法获得这种效果。如果我移除外观,那么我就能够产生这种效果
如何通过实现外观api来实现这一点?我使用以下代码解决了这个问题
[[UISearchBar appearance] setSearchFieldBackgroundImage:nil forState:UIControlStateNormal];
[[UISearchBar appearance] setBackgroundImage:nil];
[[UISearchBar appearance] setBackgroundColor:[UIColor clearColor]];
for (id img in srchbar.subviews) {
if ([img isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[img removeFromSuperview];
}
}
编辑:
上述解决方案可能导致其他显示错误。因此,最好的解决方案被标记为正确。基于
[[UISearchBar appearanceWhenContainedIn:[yourSubClassedViewControllerWhichHasSearchbar class], nil]
setBackgroundColor:[UIColor orangeColor]];