您的位置:首页 > 产品设计 > UI/UE

替换UISearchBar的取消按钮

2016-04-18 14:40 633 查看
 
MySearch = [[UISearchBaralloc]initWithFrame:CGRectMake(0,0,KWIDTH,60)];

MySearch.delegate=self;

MySearch.showsCancelButton=YES;

// [MySearch setTintColor:[UIColor redColor]];   //设置闪烁输入的头的颜色

// [MySearch setBarTintColor:[UIColor greenColor]];   //设置输入框的Bar的背景颜色

MySearch.placeholder=@"请输入客户名称、条码搜索...";

//遍历搜索条的上面的所有子视图,取下标为0的(Cancel按钮)取出Cancel上的所有子视图

for(UIView *viewin  [[[MySearchsubviews]objectAtIndex:0]subviews])

{

//找到继承UINavigationButton类的View,继承过来

if([viewisKindOfClass:[NSClassFromString(@"UINavigationButton")class]])

{

//创建一个按钮,继承上面的继承的View

UIButton * cancel =(UIButton *)view;

cancel.bounds=CGRectMake(0,0,30,30);

//            [cancel setImage:[UIImage imageNamed:@"01.png"] forState:UIControlStateNormal];

//[cancel setBackgroundImage:[UIImage imageNamed:@"01.png"] forState:UIControlStateNormal];

//[cancel setTitle:@"取消" forState:UIControlStateNormal];

[cancel  setTintColor:[UIColorblackColor]];

[cancel.titleLabelsetTextColor:[UIColorblackColor]];

}

}

[self.viewaddSubview:MySearch];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: