博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
改变UITextField中的系统控件的大小及位置
阅读量:7236 次
发布时间:2019-06-29

本文共 3618 字,大约阅读时间需要 12 分钟。

hot3.png

参考文章:

1.写一个继承于UITextField的子类,例如:SFCustomTextField;

2.在相应的重写方法中加入你想要的操作

3.用SFCustomTextField创建相应的对象

#import "SFCustomTextField.h"

@implementation SFCustomTextField

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

  • (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/

-(CGRect)clearButtonRectForBounds:(CGRect)boundst

{ //获取clearButton的系统位置及大小     CGRect rect = [super clearButtonRectForBounds:boundst]; //将clearButton沿着X轴移动 -10个单位长度后,返回相应的rect     return CGRectOffset(rect, -10, 0);

}

  • (CGRect)editingRectForBounds:(CGRect)bounds {

    CGRect rect = [super editingRectForBounds:bounds]; //应用于调整rect的insets         UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0 ,5);

    return UIEdgeInsetsInsetRect(rect, insets);

}

@end

在其他类中使用SFCustomTextField,创建对象

#import "SFBindingOfAcountViewController.h"

@property (nonatomic, strong) SFCustomTextField *acountTextField; @property (nonatomic, strong) SFCustomTextField *passwordTextField;

@end

@implementation SFBindingOfAcountViewController

  • (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self customUI]; }

-(void)customUI {

self.normalLoginView = [SFPublicMethod initViewOnSuperview:self.view WithFrame:CGRectMake(0, CGRectGetMaxY(line1.frame), kScreenViewWidth, 100) backgroundColor:GET_COLOR(@"#ffffff")];CGSize acountLableSize = [SFPublicMethod getTextSizeWithText:@"账户名" size:CGSizeMake(kScreenViewWidth, 49.5) font:GET_FONT(15)];UILabel *acountNameLable = [SFPublicMethod addLabelWithFrame:CGRectMake(15, 0, acountLableSize.width, 49.5) LabelFont:GET_FONT(15) LabelTextColor:GET_COLOR(@"#565c67") LabelTextAlignment:NSTextAlignmentLeft SuperView:self.normalLoginView LabelTag:773 LabelText:@"账户名"];UIView *line2 = [SFPublicMethod addLineViewFromPoint:CGPointMake(15, 50.5) Width:kScreenViewWidth - 15 SuperView:self.normalLoginView tag:884 withColor:GET_COLOR(@"#f2f2f2")];

UILabel *passwordNameLable = [SFPublicMethod addLabelWithFrame:CGRectMake(15, CGRectGetMaxY(line2.frame), acountLableSize.width, 49.5) LabelFont:GET_FONT(15) LabelTextColor:GET_COLOR(@"#565c67") LabelTextAlignment:NSTextAlignmentLeft SuperView:self.normalLoginView LabelTag:774 LabelText:@"密码"]; //输入的账号.密码

-------------使用SFCustomTextField创建对象---------------------------

self.acountTextField = [[SFCustomTextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(acountNameLable.frame) + 18, 0,kScreenViewWidth - CGRectGetMaxX(acountNameLable.frame) - 18, 49.5)];self.acountTextField.placeholder = @"用户名/邮箱/手机号";self.acountTextField.textColor = GET_COLOR(@"#000000");self.acountTextField.clearButtonMode = UITextFieldViewModeWhileEditing;self.acountTextField.delegate = self;self.acountTextField.tag = 990;[self.normalLoginView addSubview:self.acountTextField];self.acountTextField.font = GET_FONT(15);[self.acountTextField becomeFirstResponder];

---------------------使用SFCustomTextField创建对象-----------------------------

self.passwordTextField = [[SFCustomTextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(passwordNameLable.frame) + 18, CGRectGetMinY(passwordNameLable.frame),kScreenViewWidth - CGRectGetMaxX(passwordNameLable.frame) - 18, 49.5)];self.passwordTextField.placeholder = @"请输入密码";self.passwordTextField.textColor = GET_COLOR(@"#000000");self.passwordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;self.passwordTextField.delegate = self;self.passwordTextField.tag = 991;[self.normalLoginView addSubview:self.passwordTextField];self.passwordTextField.font = GET_FONT(15);_passwordTextField.secureTextEntry = YES;

}

@end

转载于:https://my.oschina.net/daxiaLKS/blog/699972

你可能感兴趣的文章
【mac】mac上安装JDK
查看>>
JS面试题(一)
查看>>
C语言文件I/O
查看>>
python 使用__future__
查看>>
c# 串口问题
查看>>
低配置电脑播放 flash 视频时 占 cpu 资源过高的解决方法
查看>>
linux下ssh/sftp配置和权限设置
查看>>
js面向对象编程两个主要点
查看>>
Xml通用操作类
查看>>
CSS常见以及解决兼容办法
查看>>
含参数的二次不等式的解法【中级和高阶辅导】
查看>>
Windows Phone 8初学者开发—第9部分:Windows Phone 8模拟器概述
查看>>
利用border-radious画图形
查看>>
Java并发编程(二)同步
查看>>
linux下top命令查看cpu占用情况
查看>>
jenkins+maven+junit构建自动化测试,整合junit xml生成直观的测试报告[留存]
查看>>
ol,ul,dl,table标签的基本语法
查看>>
bzoj4197
查看>>
又是每周作业~4.1
查看>>
理解项目编辑器---part1:创建项目编辑器
查看>>