这是UITextfiled子类代码:
- (instancetype)init{ self = [super init]; if (self) { self.edgeInsets = UIEdgeInsetsMake(7,10,15); } return self;}- (ID)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { self.edgeInsets = UIEdgeInsetsMake(7,15); } return self;}-(ID)initWithCoder:(NSCoder *)aDecoder{ self = [super initWithCoder:aDecoder]; if(self){ self.edgeInsets = UIEdgeInsetsMake(7,15); } return self;}- (CGRect)textRectForBounds:(CGRect)bounds { return [super textRectForBounds:UIEdgeInsetsInsetRect(bounds,self.edgeInsets)];}- (CGRect)editingRectForBounds:(CGRect)bounds { return [super editingRectForBounds:UIEdgeInsetsInsetRect(bounds,self.edgeInsets)];}
这是我使用这个类的代码:
// alloc / init _myTextFIEld.delegate = self; _myTextFIEld.backgroundcolor = [UIcolor whitecolor]; _myTextFIEld.layer.masksToBounds = YES; _myTextFIEld.layer.cornerRadius = 3.0; _myTextFIEld.returnKeyType = UIReturnKeyDone; _myTextFIEld.clearbuttonMode = UITextFIEldviewmodeWhileEditing; _myTextFIEld.autocAPItalizationType = UITextautocAPItalizationTypeWords; _myTextFIEld.autocorrectionType = UITextautocorrectionTypeNo; _myTextFIEld.hIDden = YES; _tfbutton = [UIbutton buttonWithType:UIbuttonTypeSystem]; [_tfbutton setimage:[UIImage imagenamed:@"ic_edit"] forState:UIControlStatenormal]; [self fs_addSubvIEw:_tfbutton]; [_tfbutton constrainWIDth:22.]; [_tfbutton setTintcolor:[UIcolor greencolor]]; [_tfbutton constrainHeight:22.]; [_tfbutton constrainToRightOfVIEw:_myTextFIEld margin:-25.0]; [_tfbutton constrainEqualCenterYWithVIEw:_myTextFIEld offset:0.0]; [_tfbutton setUserInteractionEnabled:NO]; UIVIEw *leftVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,5,5)]; _myTextFIEld.leftVIEw = leftVIEw; _myTextFIEld.leftviewmode = UITextFIEldviewmodeAlways;解决方法 你的代码是完全正确的.问题来自UITextFIEld类.
当您在故事板中放入UITextFIEld时,将其FontSize和minFontSize设置为50.此系统textFIEld将与您的自定义textFIEld具有相同的问题.
这只是因为UITextFIEld不知道如何在狭窄的空间中绘制大字体.
我使用了textFIEld的子类(默认高度为30),在将字体大小更改为7之后,一切正常.
总结以上是内存溢出为你收集整理的ios – UITextField文本在左侧不滚动全部内容,希望文章能够帮你解决ios – UITextField文本在左侧不滚动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)