#pragma mark searchBar開始輸入文字時spa
//漢化取消按鈕orm
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{it
searchBar.showsCancelButton = YES;io
if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0) {class
for(id cc in [searchBar subviews]) {
float
for (id zz in [cc subviews]) {di
if([zz isKindOfClass:[UIButton class]])
view
{vi
UIButton *btn = (UIButton *)zz;void
[btn setTitle:@"取消" forState:UIControlStateNormal];
}
}
}
}else{
for(id cc in [searchBar subviews])
{
if([cc isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)cc;
[btn setTitle:@"取消" forState:UIControlStateNormal];
}
}
}
}
//取消clearButton
//IOS7之前的作法
for (UIView* v in searchBar.subviews)
{
if ( [v isKindOfClass: [UITextField class]] )
{
UITextField *tf = (UITextField *)v;
tf.delegate = self;
tf.clearButtonMode = UITextFieldViewModeAlways; //老是顯示
tf.clearButtonMode = UITextFieldViewModeNever; //取消顯示
break;
}
}
我試過了沒有用,若是我設置tf.clearButtonMode = UITextFieldViewModeNever,xbutton就不顯示了。
//IOS7之後的作法
for(id cc in [_goodsSearchBar subviews]) {
for (id zz in [cc subviews]) {
if([zz isKindOfClass:[UITextField class]]){
UITextField *tf = (UITextField *)zz;
//tf.delegate = self;
tf.clearButtonMode = UITextFieldViewModeNever;
break;
}
}
}