Xcode搜索框,样式不但丑陋,在开发中往往不能直接拿去使用,需要做一定的修改,本文仅仅对如何修改背景灰色框提出个人的一些修改意见.通过一个很简单的的方法就能让你的背景视图变成你想要的图片或者颜色.
UISearchBar *searchBar =[[UISearchBar alloc]init];
searchBar.frame =CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50);
searchBar.placeholder =@"业务名字/地址/网点编号";
searchBar.delegate =self;
[self.view addSubview:searchBar];
这样我们创建好的搜索框,是带了一块灰色背景的,如果你了解searchBar的子视图结构,就很容易修改掉了.下面我们加一层视图,视图背景色或者背景图片你可以自己设定为你需要的颜色和图片.
UIView *imageView = [[UIView alloc]initWithFrame:searchBar.bounds];
imageView.backgroundColor =[UIColor whiteColor];
[searchBar insertSubview:imageView atIndex:1];
[searBarView addSubview:searchBar];