-
-
Save HamGuy/4f5f1df2f7250a4388b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSCodingSearchBar.h" | |
// ------------------------------------------------------------------------------------------ | |
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment