小编nsc*_*ing的帖子

在iOS 7上UISearchBar左对齐占位符文本?

在iOS 7 UISearchBar上,占位符文本居中,我想禁用它并使它始终像以前一样粘在左边.

在此输入图像描述

在diffs上有一个私有方法setCenterPlaceholder,并且用BOOL调用它会使之旅行.https://gist.github.com/nscoding/7220368

头文件

@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
Run Code Online (Sandbox Code Playgroud)

实施文件

#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:"]); …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uisearchbar ios

14
推荐指数
1
解决办法
1万
查看次数

标签 统计

cocoa-touch ×1

ios ×1

uisearchbar ×1