iOS 7'de UISearchBar, yer tutucu metni ortalanır ve bunu devre dışı bırakmak ve daha önce olduğu gibi sola yapışmasını sağlamak istiyorum.iOS 7'de UISearchBar, yer tutucu metnini hizaladı mı?
Orada özel bir yöntem setCenterPlaceholder fark dosyaları üzerinde, ve bir BOOL ile bu çağıran gezisi yapacak. https://gist.github.com/nscoding/7220368
Başlık dosyası
@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
Uygulama dosyasını
#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
aynı şeyi yapar başka değil, "Hacky yol" olup olmadığını merak ediyorum.
söz konusu kod içeren olması tercih edilebilirse, yerine sadece ona bağlanıyor. –
Bunu denediniz mi? http://stackoverflow.com/a/19555305/2155985 –
Bunun iyi bir fikir olduğunu sanmıyorum. Standartları mümkün olduğunca sağlam tutmaya çalışmalısın. – anders