2012-03-14 116 views

回答

0

我這樣做一次..我用自定義按鈕進行自定義操作更換清除按鈕..請檢查此

UISearchBar *searchBar = yourSearchController.searchBar; 
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];//your button image. 
cButton.contentMode = UIViewContentModeScaleToFill; 
[cButton addTarget:self action:@selector(customButtonPressed) forControlEvents:UIControlEventTouchUpInside];//This is the custom event 
[searchtextfield setRightView:cButton]; 
[searchtextfield setRightViewMode:UITextFieldViewModeAlways]; 

好運。

+0

對不起,其實意味着清除按鈕不是取消按鈕。 這解釋了搜索字段右側的小按鈕。 我編輯了問題來說清楚按鈕。但感謝您花時間。 – 2012-03-14 15:16:09

+0

耶和我的答案爲這個按鈕:) – 2012-03-14 15:18:26

+0

更新了圖片的清晰度;-) – 2012-03-14 15:34:22