您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页ios UIsearchbar如何使放大镜图片和placeho

ios UIsearchbar如何使放大镜图片和placeho

来源:二三娱乐

直接看效果:
原效果:


369E0D1A-671C-40F2-8CC2-53D0F949E1C1.png

居左后:

E9C3146C-0C95-4554-984A-A9AEF70C0A9C.png

写一个UIsearchbar 的扩展类,


DA7D9BBA-30CB-45CF-8E5B-DCE4AD8E43AF.png

.h文件

@interface UISearchBar (Extension)
-(void)setLeftPlaceholder:(NSString *)placeholder;
@end

.m文件实现

-(void)setLeftPlaceholder:(NSString *)placeholder {
self.placeholder = placeholder;

SEL centerSelector = NSSelectorFromString([NSString stringWithFormat:@"%@%@", @"setCenter", @"Placeholder:"]);
if ([self respondsToSelector:centerSelector]) {
    BOOL centeredPlaceholder = NO;
    NSMethodSignature *signature = [[UISearchBar class] instanceMethodSignatureForSelector:centerSelector];
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
    [invocation setTarget:self];
    [invocation setSelector:centerSelector];
    [invocation setArgument:&centeredPlaceholder atIndex:2];
    [invocation invoke];
}

}

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务