UISearchBar placeholder左对齐

来源:互联网 发布:淘宝美工论坛邀请码 编辑:程序博客网 时间:2024/04/29 17:59
@interface NSCodingSearchBar : UISearchBar // Default by the system is YES.// https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UISearchBar.h@property (nonatomic, assign, setter = setHasCentredPlaceholder:) BOOL hasCentredPlaceholder; @end

 @implementation NSCodingSearchBar  // ------------------------------------------------------------------------------------------#pragma mark - Initializers// ------------------------------------------------------------------------------------------- (instancetype)initWithFrame:(CGRect)frame{    if ((self = [super initWithFrame:frame]))    {        self.hasCentredPlaceholder = YES;    }        return self;}  // ------------------------------------------------------------------------------------------#pragma mark - Methods// ------------------------------------------------------------------------------------------- (void)setHasCentredPlaceholder:(BOOL)hasCentredPlaceholder{    _hasCentredPlaceholder = hasCentredPlaceholder;        SEL centerSelector = NSSelectorFromString([NSString stringWithFormat:@"%@%@", @"setCenter", @"Placeholder:"]);    if ([self respondsToSelector:centerSelector])    {        NSMethodSignature *signature = [[UISearchBar class] instanceMethodSignatureForSelector:centerSelector];        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];        [invocation setTarget:self];        [invocation setSelector:centerSelector];        [invocation setArgument:&_hasCentredPlaceholder atIndex:2];        [invocation invoke];    }    }  @end


0 0