我在xib中有一个UISearchbar
,占位符没有完美设计。
见图片
答案 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;