Hacky to solve IOS 7 Uisearchbar default text left display problem

Source: Internet
Author: User

reference: On IOS 7 Uisearchbar left ALIGN PLACEHOLDER TEXT?

Control code: HTTPS://GIST.GITHUB.COM/COCRASH/DE56F5F0B70B7EB6D6E3

A private method, Setcenterplaceholder, modifies this boolean value at the time of invocation to achieve the effect of modifying the position.

1 @interface Nscodingsearchbar:uisearchbar 2  3 // Default by the system is YES. 4 // Https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UISearchBar.h 5 @property (nonatomic, assign, setter = Sethascentredplaceholder:) BOOL Hascentredplaceholder; 6  7 @end

Implementation file:

1 @implementationNscodingsearchbar2  3  4 // ------------------------------------------------------------------------------------------5 #pragmaMark-initializers6 // ------------------------------------------------------------------------------------------7-(Instancetype) initWithFrame: (CGRect) Frame8 {9     if(self =[Super Initwithframe:frame]))Ten     { OneSelf.hascentredplaceholder =YES; A     } -      -     returnSelf ; the } -   -   - // ------------------------------------------------------------------------------------------ + #pragmaMark-methods - // ------------------------------------------------------------------------------------------ +- (void) Sethascentredplaceholder: (BOOL) Hascentredplaceholder A { at_hascentredplaceholder =Hascentredplaceholder; -      -SEL centerselector = nsselectorfromstring ([NSString stringWithFormat:@"%@%@",@"SetCenter",@"Placeholder:"]); -     if([self respondstoselector:centerselector]) -     { -Nsmethodsignature *signature = [[Uisearchbarclass] instancemethodsignatureforselector:centerselector]; inNsinvocation *invocation =[Nsinvocation invocationwithmethodsignature:signature]; - [invocation settarget:self]; to [invocation setselector:centerselector]; +[Invocation Setargument:&_hascentredplaceholder Atindex:2]; - [invocation invoke]; the     } *      $ }Panax Notoginseng   -   the @end

Hacky to solve IOS 7 Uisearchbar default text left display problem

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.