Reputation: 797
I created a UISearchBar with 100 as height but it does not take up the size and it is of default size 44. Is there anyway to size the height of UISearchBar?
Upvotes: 4
Views: 13087
Reputation: 3308
You can set a custom image for the searchfield and that will allow you to create a different sized control
[searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"SearchTextbox"] forState:UIControlStateNormal];
You can manually override the searchbar height inside layoutSubViews
like this
- (void)layoutSubviews {
frame = self.frame;
if (frame.size.height != 100) {
frame.size.height = 100;
self.frame = frame;
}
}
Upvotes: 2
Reputation: 6958
If I understand your question correctly, you are trying to resize the UISearchBar, is that right? Have you tried adjusting the size of its frame?
NSLog(@"Adding UISearchBar to myView.");
UISearchBar *searchBar = [[UISearchBar alloc] init];
[myView addSubview:searchBar];
// Make the search bar will take up the entire window.
searchBar.frame = [[UIApplication sharedApplication] keyWindow].frame;
// Release the searchBar (it is being retained by myView)
[searchBar release];
If you are trying to change the size of the UITextField subview within the UISearchBar, I am afraid you're out of luck, as detailed on this post on SO. The UITextField inside of a UISearchBar is a part of the private API, an instance of UISearchBarTextField, and you cannot change it's size (in any way Apple will approve of, that is). UISearchBar does offer ways to change the offset of the text within a UISearchBar, however. Consult the documentation for the UISearchBar class.
Upvotes: 0