swiftswift3.0自己封装的快速构建页面的方法
2017-04-28 10:02
363 查看
//#param mark 控件
func creatLabel(frame:CGRect,text:String,textColor:UIColor,textFont:CGFloat,textAlignment:NSTextAlignment)
-> UILabel {
let label =
UILabel.init(frame: frame)
label.text = text
label.textColor = textColor
label.font =
UIFont.systemFont(ofSize: textFont)
label.textAlignment = textAlignment
scorllView!.addSubview(label)
return label
}
func creatBtn(frame:CGRect,text:String,textColorNor:UIColor,textColorHig:UIColor,textFont:CGFloat,imageNor:String,imageHig:String,btnSet:Bool,target:Selector,textAlignment
: NSTextAlignment,borderColor :
UIColor) -> UIButton {
let btn =
UIButton.init(frame: frame)
btn.setTitle(text, for: .normal)
btn.setTitleColor(textColorNor, for: .normal)
btn.setTitleColor(textColorHig, for: .selected)
btn.setTitleColor(textColorHig, for: .highlighted)
btn.setImage(UIImage.init(named: imageNor), for: .normal)
btn.setImage(UIImage.init(named: imageHig), for: .highlighted)
btn.setImage(UIImage.init(named: imageHig), for: .selected)
btn.isEnabled = btnSet
if
IS_IPHONE_4_OR_LESS {
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 45,
5, -(UIScreen.main.bounds.width
/ 2 - 115))
}
if
IS_IPHONE_5 ||
IS_IPHONE_SE{
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 45,
5, -(UIScreen.main.bounds.width
/ 2 - 115))
}
if
IS_IPHONE_6 ||
IS_IPHONE_7{
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 55,
5, -(UIScreen.main.bounds.width
/ 2 - 130))
}
if
IS_IPHONE_6P ||
IS_IPHONE_7P{
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 60,
5, -(UIScreen.main.bounds.width
/ 2 - 150))
}
btn.layer.masksToBounds =
true
btn.layer.cornerRadius =
5
btn.layer.borderColor = borderColor.cgColor
btn.layer.borderWidth =
1
btn.titleLabel?.font =
UIFont.systemFont(ofSize: textFont)
btn.titleLabel?.textAlignment = textAlignment
if btn.isEnabled
== true {
btn.backgroundColor =
UIColor.white
}else {
btn.backgroundColor =
UIColor.white
}
btn.addTarget(self, action: target, for: .touchUpInside)
scorllView!.addSubview(btn)
return btn
}
func textfield(frame:CGRect,text:String,textFont:CGFloat,textColor:UIColor,textAlignment:NSTextAlignment,placeholder:String,borderStyle:UITextBorderStyle,borderColor
: UIColor) -> UITextField {
let textfield =
UITextField.init(frame: frame)
textfield.font =
UIFont.systemFont(ofSize: textFont)
textfield.textColor = textColor
textfield.textAlignment = textAlignment
textfield.placeholder = placeholder
textfield.delegate =
self
textfield.borderStyle = borderStyle
textfield.clearButtonMode =
UITextFieldViewMode.whileEditing
//叉号一直显示
textfield.adjustsFontSizeToFitWidth =
true
textfield.backgroundColor =
UIColor.white
textfield.keyboardType =
UIKeyboardType.default
textfield.layer.masksToBounds =
true
textfield.layer.cornerRadius =
5
textfield.layer.borderColor = borderColor.cgColor
textfield.layer.borderWidth =
1
scorllView!.addSubview(textfield)
return textfield
}
func textFieldView(frame:CGRect,text:String,textFont:CGFloat,textColor:UIColor,textAlignment:NSTextAlignment,placeholder:String,borderColor
: UIColor) -> WTextVIew {
let textFieldView =
WTextVIew.init(frame: frame)
textFieldView.font =
UIFont.systemFont(ofSize: textFont)
textFieldView.textColor = textColor
textFieldView.textAlignment = textAlignment
textFieldView.delegate =
self
textFieldView.text = text
textFieldView.layer.masksToBounds =
true
textFieldView.layer.cornerRadius =
5
textFieldView.layer.borderWidth =
1
textFieldView.layer.borderColor = borderColor.cgColor
textFieldView.backgroundColor =
UIColor.white
textFieldView.placeholder = placeholder
scorllView!.addSubview(textFieldView)
return textFieldView
}
func creatLabel(frame:CGRect,text:String,textColor:UIColor,textFont:CGFloat,textAlignment:NSTextAlignment)
-> UILabel {
let label =
UILabel.init(frame: frame)
label.text = text
label.textColor = textColor
label.font =
UIFont.systemFont(ofSize: textFont)
label.textAlignment = textAlignment
scorllView!.addSubview(label)
return label
}
func creatBtn(frame:CGRect,text:String,textColorNor:UIColor,textColorHig:UIColor,textFont:CGFloat,imageNor:String,imageHig:String,btnSet:Bool,target:Selector,textAlignment
: NSTextAlignment,borderColor :
UIColor) -> UIButton {
let btn =
UIButton.init(frame: frame)
btn.setTitle(text, for: .normal)
btn.setTitleColor(textColorNor, for: .normal)
btn.setTitleColor(textColorHig, for: .selected)
btn.setTitleColor(textColorHig, for: .highlighted)
btn.setImage(UIImage.init(named: imageNor), for: .normal)
btn.setImage(UIImage.init(named: imageHig), for: .highlighted)
btn.setImage(UIImage.init(named: imageHig), for: .selected)
btn.isEnabled = btnSet
if
IS_IPHONE_4_OR_LESS {
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 45,
5, -(UIScreen.main.bounds.width
/ 2 - 115))
}
if
IS_IPHONE_5 ||
IS_IPHONE_SE{
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 45,
5, -(UIScreen.main.bounds.width
/ 2 - 115))
}
if
IS_IPHONE_6 ||
IS_IPHONE_7{
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 55,
5, -(UIScreen.main.bounds.width
/ 2 - 130))
}
if
IS_IPHONE_6P ||
IS_IPHONE_7P{
btn.titleEdgeInsets =
UIEdgeInsetsMake(0,
-20, 0,
40)
btn.imageEdgeInsets =
UIEdgeInsetsMake(5,UIScreen.main.bounds.width
/ 2 - 60,
5, -(UIScreen.main.bounds.width
/ 2 - 150))
}
btn.layer.masksToBounds =
true
btn.layer.cornerRadius =
5
btn.layer.borderColor = borderColor.cgColor
btn.layer.borderWidth =
1
btn.titleLabel?.font =
UIFont.systemFont(ofSize: textFont)
btn.titleLabel?.textAlignment = textAlignment
if btn.isEnabled
== true {
btn.backgroundColor =
UIColor.white
}else {
btn.backgroundColor =
UIColor.white
}
btn.addTarget(self, action: target, for: .touchUpInside)
scorllView!.addSubview(btn)
return btn
}
func textfield(frame:CGRect,text:String,textFont:CGFloat,textColor:UIColor,textAlignment:NSTextAlignment,placeholder:String,borderStyle:UITextBorderStyle,borderColor
: UIColor) -> UITextField {
let textfield =
UITextField.init(frame: frame)
textfield.font =
UIFont.systemFont(ofSize: textFont)
textfield.textColor = textColor
textfield.textAlignment = textAlignment
textfield.placeholder = placeholder
textfield.delegate =
self
textfield.borderStyle = borderStyle
textfield.clearButtonMode =
UITextFieldViewMode.whileEditing
//叉号一直显示
textfield.adjustsFontSizeToFitWidth =
true
textfield.backgroundColor =
UIColor.white
textfield.keyboardType =
UIKeyboardType.default
textfield.layer.masksToBounds =
true
textfield.layer.cornerRadius =
5
textfield.layer.borderColor = borderColor.cgColor
textfield.layer.borderWidth =
1
scorllView!.addSubview(textfield)
return textfield
}
func textFieldView(frame:CGRect,text:String,textFont:CGFloat,textColor:UIColor,textAlignment:NSTextAlignment,placeholder:String,borderColor
: UIColor) -> WTextVIew {
let textFieldView =
WTextVIew.init(frame: frame)
textFieldView.font =
UIFont.systemFont(ofSize: textFont)
textFieldView.textColor = textColor
textFieldView.textAlignment = textAlignment
textFieldView.delegate =
self
textFieldView.text = text
textFieldView.layer.masksToBounds =
true
textFieldView.layer.cornerRadius =
5
textFieldView.layer.borderWidth =
1
textFieldView.layer.borderColor = borderColor.cgColor
textFieldView.backgroundColor =
UIColor.white
textFieldView.placeholder = placeholder
scorllView!.addSubview(textFieldView)
return textFieldView
}
相关文章推荐
- ASP.NET 快速构建应用程序页面主框架
- Javascript访问Cookie的四个基本方法无论是在创建页面还是构建对象都会使用到,单独拿出来备用:
- 将自己写的经常复用的类封装成dll/lib的方法
- 前台页面查询参数多的话,建议将其封装成querybean传到DAO层,在DAO层构建SQL语句:例子
- 利用CentOS快速构建自己的发行版(3)
- 基于功能更丰富的基础类构建您自己的 ASP.NET 页面
- 对HibernateTemplate的扩展:封装上自己需要的逻辑形成新方法(不断更新)
- 基于功能更丰富的基础类构建您自己的 ASP.NET 页面
- 基于功能更丰富的基础类构建您自己的 ASP.NET 页面
- 10种构建J2EE方法让架构设计师快速成为专家
- 基于功能更丰富的基础类构建您自己的 ASP.NET 页面
- PHP程序百行代码快速构建简易聊天室方法
- 基于功能更丰富的基础类构建您自己的 ASP.NET 页面
- 将自己写的经常复用的类封装成dll/lib的方法
- 基于功能更丰富的基础类构建您自己的 ASP.NET 页面
- Joekoe 4.0 CMS 免费版本最基本的修改方法和地方汇总(快速修改成自己的站)
- 使用VS快速将类方法封装成Web服务
- 自己封装的一个ASP.NET上传文件的方法
- 利用CentOS快速构建自己的发行版(1)
- BS中利用JS控制页面显示本地图片,自己封装的控件。