i will like to know how do i need to change a UISearchBar from the default round curve to a rectangle.
Much better in my opinion:
UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"];
txfSearchField.borderStyle = UITextBorderStyleNone;
for (UIView *searchBarSubview in [mySearchBar subviews]) {
if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {
@try {
[(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleRoundedRect];
}
@catch (NSException * e) {
// ignore exception
}
}
}
Swift 4:
mySearchBar.subviews().forEach { searchBarSubview in
if searchBarSubview is UITextInputTraits {
do {
(searchBarSubview as? UITextField)?.borderStyle = .roundedRect
} catch {
// ignore exception
}
}
}
Swift 3
let textFieldInsideUISearchBar = searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideUISearchBar?.borderStyle = .none
textFieldInsideUISearchBar?.backgroundColor = UIColor.white
Simple add background image, left view and right view for your TextField.
Example below
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 10., nameField.bounds.size.height)];
nameField.leftView = leftView;
nameField.leftViewMode = UITextFieldViewModeAlways;
leftView release];
In the target image I don't see the default shadow, so I'll mention that setting the background property to nil will remove it. I needed to do this in my project and removing the image and manipulating the border works well. I had to cast the control to get to the background property.
UITextField * x = (UITextField*)searchBarSubview;
x.background = nil;
@Keller thanks for the tip for finding the control.
UISearchBar has the round curve, and it is fix if you like to make it rectangle you have to use custom search bar with rectangular image as like of search bar and 1 uibutton and UItextfield, and your own searching logic