UISearchbar占位符错位

时间:2014-09-25 06:06:37

标签: ios uisearchbar placeholder

我在xib中有一个UISearchbar,占位符没有完美设计。

见图片enter image description here

1 个答案:

答案 0 :(得分:3)

UITextField *txtField = [UITextField appearanceWhenContainedIn:[UISearchBar class], nil];
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 8, 20)];
    paddingView.backgroundColor = [UIColor grayColor];
    [txtField setLeftViewMode:UITextFieldViewModeAlways];
    [txtField setLeftView:paddingView];
    txtField.delegate = self;
    [txtField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
    txtField.textAlignment = UITextAlignmentLeft;