首页 > 代码库 > UITextField实现左侧空出一定的边距

UITextField实现左侧空出一定的边距

就是通过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;}

 

UITextField实现左侧空出一定的边距