2012-01-12 28 views
0

UIsearchBarの背景を非表示にする以下のコードは、iOS4.2までは正常に動作しますが、iOS4.3以降では正常に動作します。iOS5でUISearchBarの背景を非表示にする

for (UIView *subview in searchBar.subviews) { 
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) { 
     [subview removeFromSuperview]; 
     break; 
    } 
} 
+0

外観APIのためにビュー階層が変更されている可能性があります。 '-viewDidLoad'にブレークポイントを設定し、プログラムが一時停止している間はコンソールに' po [searchBar recursiveDescription] 'と入力して、プライベートクラス名を含むビュー階層全体のリストを取得します。 –

+0

@Mark Adams - Nibが私のために働いたのではなく、プログラムでUIsearchBarを作成する – iOSPawan

+1

'-initWithFrame:'でコードを実行しているのなら、それは明らかです。ペン先から読み込むには '-initWithCoder:'初期化子を使います。 –

答えて

1

彼らのこのコードには問題はありません....しかし、また、あなたの代替ソリューションを与えて、私はそれが遅れている知っているが、ここで参照することがある

[[[searchBar subviews] objectAtIndex:0] removeFromSuperview]; 
0

にループ用のコードを置き換えます

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT、0)、^ { CGRect RECT = CGRectMake(は0.0f、0.0fを、1.0F、1.0F); UIGraphicsBeginImageContext(rect.size); UIImage *画像=ゼロ、 CGContextRef context = UIGraphicsGetCurrentContext(); if(context){ CGContextSetFillColorWithColor(context、[UIColor clearColor] .CGColor); CGContextFillRect(context、rect); イメージ= UIGraphicsGetImageFromCurrentImageContext(); } UIGraphicsEndImageContext(); iOSの7別のUIViewで

dispatch_async(dispatch_get_main_queue(), ^{ 
     self.backgroundImage = image; 
    }); 
}); 
3

UISearchBarに加えて、ここではiOSの7のためのソリューションです:

UIView *vw = [yourSearchBar.subviews objectAtIndex:0]; 
for (id img in vw.subviews) { 
    if ([img isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) { 
     [img removeFromSuperview]; 
    } 
} 

あなたはまた、(また、iOSの7で動作します)次の手順を実行できます。

[yourSearchBar setBackgroundImage:[UIImage new]]; 
[yourSearchBar setTranslucent:YES]; 
関連する問題