Skip to content

Instantly share code, notes, and snippets.

@dong
Forked from nscoding/NSCSearchBar.h
Last active September 11, 2015 05:33
Show Gist options
  • Save dong/fbbda8fb649cc8c5eb55 to your computer and use it in GitHub Desktop.
Save dong/fbbda8fb649cc8c5eb55 to your computer and use it in GitHub Desktop.

Revisions

  1. @nscoding nscoding revised this gist Oct 29, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion NSCSearchBar.h
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@

    @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
  2. @nscoding nscoding revised this gist Oct 29, 2013. 2 changed files with 0 additions and 2 deletions.
    1 change: 0 additions & 1 deletion NSCSearchBar.h
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@


    @interface NSCodingSearchBar : UISearchBar

    // Default by the system is YES.
    1 change: 0 additions & 1 deletion NSCSearchBar.m
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    #import "NSCodingSearchBar.h"


  3. @nscoding nscoding created this gist Oct 29, 2013.
    8 changes: 8 additions & 0 deletions NSCSearchBar.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@


    @interface NSCodingSearchBar : UISearchBar

    // Default by the system is YES.
    @property (nonatomic, assign, setter = setHasCentredPlaceholder:) BOOL hasCentredPlaceholder;

    @end
    46 changes: 46 additions & 0 deletions NSCSearchBar.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@

    #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