Sur iOS 7, UISearchBar a aligné le texte de l'espace réservé?

Sur iOS 7 UISearchBar le texte de l'espace réservé est centré et je veux le désactiver et de le rendre toujours stick vers la gauche, comme il était avant.

Sur iOS 7, UISearchBar a aligné le texte de l'espace réservé?

Il y a une méthode privée setCenterPlaceholder, sur les diffs et ce avec un BOOL feront de ce voyage. https://gist.github.com/nscoding/7220368

Fichier d'en-tête

@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

Mise en œuvre de fichier

#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

Je me demandais si il y est tout autre, et non pas "Hacky façon" qui fait la même chose.

source d'informationauteur nscoding