Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 目标C-改变控制外观,实施外观api_Ios_Objective C_Uisearchbar_Uiappearance - Fatal编程技术网

Ios 目标C-改变控制外观,实施外观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

我正在使用外观api定制
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]];