1, custom Uisearchbar subclass Mysearchbar, rewrite Layoutsubviews method.
Code:
-(void) layoutsubviews {
[super layoutsubviews];
For (UIView *view in self.subviews)
{
if ([View iskindofclass:nsclassfromstring (@ "UIView")] && View.subviews.count > 0) {for
(UIView *subview in view.subviews) {
if (Subview iskindofclass: Nsclassfromstring (@ "Uitextfield")]) {
Uitextfield *textfield = (Uitextfield *) Subview;
CGRect frame = textfield.frame;
Frame.size.height =;
Textfield.frame = frame;
Textfield.font = [Uifont fontwithname:@ "Helvetica" size:17.0f];
break;
}
}
break;
}}}
2, if the Uisearchbar is defined in a xib file, do the following in the Awakefromnib method:
For (UIView *view in self.destinationSearchBar.subviews)
{
if ([View iskindofclass:nsclassfromstring (@) UIView ")] && view.subviews.count > 0) {
[[view.subviews objectatindex:0] removefromsuperview];
CGRect frame = view.frame;
CGFloat height = frame.size.height + 8;
frame.size.height = height;
View.frame = frame;
View.clipstobounds = NO;
break;
}
}
If it is generated using the Alloc/init method, add the code in its corresponding Uviewcontroller Viewdidload method