给UItextFiled左侧设置小图片
创建类方法
+(void)setTextFiledLeftImage:(UITextField*)textFiled image:(NSString*)image{
textFiled.leftViewMode=UITextFieldViewModeAlways;
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, 20, 20)];
imageview.image = [UIImage imageNamed:image];
[view addSubview:imageview];
// 在文本框左侧预留一些空隙
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, 10, 20)];
paddingView.backgroundColor = [UIColor clearColor];
[view addSubview:paddingView];
textFiled.leftView = view;
textFiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
}
直接类方法 调用即可
Simulator Screen Shot 2017年5月17日 下午4.45.51.png
网友评论