就是通过uitextfield的leftview来实现的,同时要设置leftviewmode。
如果设置左右边距,需要再加上rightView功能
-(void)setTextFieldLeftPadding:(UITextField *)textField forWidth:(CGFloat)leftWidth { CGRect frame = textField.frame; frame.size.width = leftWidth; UIView *leftview = [[UIView alloc] initWithFrame:frame]; textField.leftViewMode = UITextFieldViewModeAlways; textField.leftView = leftview; }