2014-09-25 125 views
2

我在xib中有一個UISearchbar,佔位符不在完美設計中。UISearchbar佔位符錯位

見圖像enter image description here

+0

ù分別添加的UISearchBar在progrmatically或使用工具的方法 – 2014-09-25 06:41:26

回答

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;