Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

UISearchBar Appearance

Hi Everyone!

So, I've been playing around with UISearchBar and am a little stuck.

There is a 1px border that I can't seem to get rid of.

The code I used is below. I'm not using storyboard. Practicing it programmatically. So if there is something I could do better, please let me know. I'm open to feedback without getting my feelings hurt.

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0, 320, 44)];
[self.view addSubView:searchBar];

searchBar.barStyle = UISearchBarStyleDefault;
searchBar.barTintColor = [UIColor colorWithRed: 25.0/255.0 green:181.0/255.0 blue:254.0/255.0 alpha 1.0];
searchBar.tintColor = [UIColor colorWithRed: 25.0/255.0 green:181.0/255.0 blue:254.0/255.0 alpha 1.0];

[[UItextField appearanceWhenContainedIn: [UISearchBar class], nil] setFont:[UIFont fontWithName:@"avenirNext-ultraLight" size:16]];

So, I'm trying to get rid of the border that appears above and below and if possible and change placeholder text and the magnifying glass color.

Here's a screenshot so you can see what I'm talking about.

Thanks in advance for any help.

1 Answer

What I would do is set self.view.backgroundColor = [...] to set the whole background to blue, that way The gap would disappear via camouflage. For the content, you'll just need to make another uiview for the center.

Another approach would be setting view.layer.borderColor = [...]

Hey Richard!

Thanks a ton for answering. I also had a friend tweet me a solution as well. Here's what I did to get rid of the border:

UIColor *blueColor = [UIColor colorWithRed:25.0/255.0 green:181.0/255.0 blue:254.0/255.0 alpha:1.0];
searchBar.layer.borderColor = blueColor.CGColor;
searchBar.layer.borderWidth = 1;