2012-02-17 10 views
2

iPadのuisearchbarにSafariのようなリフレッシュロゴを追加することは可能ですか? 下の画像が気に入りましたか?uisearchbarに最新のロゴを追加する

私はuisearchbarcontrollerとuitableviewを持っています。それがリフレッシュのような矢印を追加することが可能かどうかわかります。検索結果やブックマークを追加することが可能です。

refresh icon

ありがとうございます。

答えて

4

はいあなたは..あなたがここに...あなたのリフレッシュ動作を行いますカスタムボタンとクリアボタンを交換し、する必要がありますすることができますが

UISearchBar *searchBar = yourSearchBar; 
UITextField *searchtextfield = [searchBar.subviews objectAtIndex:1]; 
UIButton *cButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
cButton.frame = CGRectMake(0, 0, 20 , 20); 
cButton.backgroundColor = [UIColor clearColor]; 
[cButton setImage:[UIImage newImageFromResource:@"yourButtonImage"] forState:UIControlStateNormal];//refresh image. 
cButton.contentMode = UIViewContentModeScaleToFill; 
[cButton addTarget:self action:@selector(refreshButtonPressed) forControlEvents:UIControlEventTouchUpInside];//This is the custom event(refresh) 
[searchtextfield setRightView:cButton]; 
[searchtextfield setRightViewMode:UITextFieldViewModeAlways]; 

が楽しむことを行うためのコードです:)

+0

ありがとう!!それは助けて! – kraitz

+0

iOS 7では動作しませんか? –

0

iOSの7の場合、交換してください:

UITextField *searchtextfield = [searchBar.subviews objectAtIndex:1]; 

で:

UITextField *searchtextfield = [((UIView *)[searchBar.subviews objectAtIndex:0]).subviews lastObject]; 
関連する問題