改变UITextField中的系统控件的大小及位置
2016-06-23 16:32
435 查看
参考文章:http://www.th7.cn/Program/IOS/201502/398980.shtml
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
{
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创建对象---------------------------
---------------------使用SFCustomTextField创建对象-----------------------------
}
@end
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
相关文章推荐
- Vuejs学习2--Vue实例
- Vuejs学习1--概述
- AIX installation guide
- Vuejs学习0
- 【iOS】UILabel 常用属性设置
- 【转】iOS开发UITableViewCell的选中时的颜色设置
- 【转】iOS UITableView的方法解析
- uicollectionview cell 行间距、列间距
- 详解build.gradle
- oledb 处理excel 报错 UPDATE “Operation must use an updateable query”
- UITableViewCell的高度自适应
- HIVE Row_Sequence 实现列自增长
- disabled="true" 的标签元素不可提交
- LeetCode—357. Count Numbers with Unique Digits
- UGUI与NGUI的区别与优缺点
- 1099. Build A Binary Search Tree
- 短序列组装Sequence Assembly(转载)
- Android消息机制---MessageQueue的工作原理
- MP 新版本 [3 mysql sequelize 数据库到前端页面渲染]
- JAVA QUEUE 队列 使用