自定義清除按鈕我想:中的UISearchBar文本字段
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 imageNamed:@"x-button"] forState:UIControlStateNormal];//your button image.
cButton.contentMode = UIViewContentModeScaleToFill;
[cButton addTarget:self action:@selector(xButtonPressed) forControlEvents:UIControlEventTouchUpInside];//This is the custom event
[searchtextfield setRightView:cButton];
[searchtextfield setRightViewMode:UITextFieldViewModeWhileEditing];
但它並不能很好地工作...... 它會顯示自定義按鈕,但是當你輸入的東西,老一所送的回.. 。
我該怎麼做?
跟隨我的回答http://stackoverflow.com/questions/13799074/how-to-override-the-cancel-button-in-the- uisearchbar/13799144#13799144 – Rajneesh071
是你的問題解決了嗎? – Rajneesh071