iOS changes the Uitextfield frame inside the Uisearchbar and removes the Uisearchbar background

Source: Internet
Author: User

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.