2012-01-25 12 views
2

私はiphoneで新しいです、私は色をクリアするために色を変更するには、検索バーの背景を変更したい。私のコードは次のとおりです。事前にipadで検索バーの背景色を変更するには

UISearchBar *mySearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(10, 550, 330, 42)]; 
mySearchBar.delegate = self; 
mySearchBar.showsCancelButton = YES; 
[email protected]"Search here.."; 
    mySearchBar.tintColor=[UIColor clearColor]; 
[self.view addSubview:mySearchBar]; 

ありがとう:

答えて

4

検索バーには、デフォルトのビューを持っていると我々は、このビューを削除するので、その後の背景色は、私がこのような何かをしたIOS 7で

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

私に返信してくれてありがとう.. ..その仕事の細かい火をつける。 – user1162034

+0

投票のためのThanx – Deepesh

0

あなたはウル背景色ごとに色合いの色を設定しようと、半透明の色を使用して設定することができます。

mySearchBar.tintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0]; 
+0

非常に@vishy ..ありがとうございます。おかげできます.. – user1162034

0
mySearchBar.backgroundColor = [UIColor clearColor]; 

代わりのtintColorを設定する検索バーののbackgroundColorを設定します。

0

明らかです。

if (self.searchDisplayController.searchBar.subviews.count >= 1) { 
     for (UIView *subview in [[self.searchDisplayController.searchBar.subviews objectAtIndex:0] subviews]) { 

      if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) { 
       [subview removeFromSuperview]; 
       break; 
      } 
     } 
    }