Insets就是css中的padding
我们给UITextField设置了leftView,目的是在文本输入框左侧显示一个图标。但是在ios7里,这个图标会紧紧地挨着TextField的左边框,很不美观,所以就希望设置一个Insets。但是直接设置ImageView的bounds不行,需要用下面这个方法:
@interface YLSTextField : UITextField
-(id)initWithFrame:(CGRect)frame Icon:(UIImageView*)icon;
@end
@implementation YLSTextField
-(id)initWithFrame:(CGRect)frame Icon:(UIImageView*)icon
{
self = [super initWithFrame:frame];
if (self) {
self.leftView = icon;
self.leftViewMode = UITextFieldViewModeAlways;
}
return self;
}
-(CGRect) leftViewRectForBounds:(CGRect)bounds {
CGRect iconRect = [super leftViewRectForBounds:bounds];
iconRect.origin.x += 10;// 右偏10
return iconRect;
}
@end
UIImage *usernameImage = [UIImage imageNamed:@"use