swift基础学习UI(01)[UIView、UILabel、UIButton]
2016-09-26 14:45
579 查看
//控件的部分使用,以此类推其他属性
//1.UIView
let firstView =
UIView()
firstView.isHidden =
true
//背景
firstView.backgroundColor =
UIColor.red;
//frame大小x、y坐标
width height 宽高只要是继承UIView的frame都可以这样设置
firstView.frame =
CGRect(x:10,y:100,width:300,height:45)
//能否响应点击事件
firstView.isUserInteractionEnabled =
true
//tag值
firstView.tag =
101
//边框的颜色
firstView.layer.borderColor =
UIColor.black.cgColor
//边框的宽度
firstView.layer.borderWidth =
2
//超过范围截取
firstView.layer.masksToBounds =
true
//边框的弧度
firstView.layer.cornerRadius =
5
//
self.view.addSubview(firstView)
//2.UILabel
//定义
let label =
UILabel()
label.isHidden =
true
//大小x、y坐标
width height 宽高
label.frame =
CGRect(x:50,y:60,width:200,height:50)
//背景颜色
label.backgroundColor =
UIColor.red
//字体颜色
label.textColor =
UIColor.white
//文字过长省略方式
label.lineBreakMode =
NSLineBreakMode.byClipping
//显示几行
label.numberOfLines =
1
//阴影
label.shadowColor =
UIColor.gray
//居中、居左
label.textAlignment =
NSTextAlignment.center
//透明度
label.alpha =
0.5
//字体粗心大小
label.font =
UIFont.boldSystemFont(ofSize:
20)
//高亮
label.isHighlighted =
true
label.highlightedTextColor =
UIColor.blue
//自适应
label.adjustsFontSizeToFitWidth =
true
self.view .addSubview(label)
//富文本:
let attribute =
NSMutableAttributedString(string:"李欢")
attribute.addAttribute(NSForegroundColorAttributeName, value:
UIColor.yellow, range:
NSMakeRange(0,
1))
label.attributedText = attribute
//UILabel本身也是继承与UIView、因此有touch
label.isUserInteractionEnabled =
true
//3.UIButton
let btn =
UIButton()
btn.isHidden =
false
btn.frame =
CGRect(x:10,y:200,width:300,height:44)
btn.backgroundColor =
UIColor.red
//btn的title highlighted、normal、等
btn.setTitle("按钮",
for: UIControlState.normal)
//颜色
btn.setTitleColor(UIColor.gray, for:
UIControlState.normal)
//图片
btn.setImage(UIImage.init(named:""),
for: UIControlState.normal)
//点击方法
btn.addTarget(self, action:#selector(click(_:)),
for:.touchUpInside)
btn.tag =
202
//以及继承UIView所具有的属性
self.view.addSubview(btw)
//点击方法
func click(_ btn:UIButton){
print(btn.tag)
}
//1.UIView
let firstView =
UIView()
firstView.isHidden =
true
//背景
firstView.backgroundColor =
UIColor.red;
//frame大小x、y坐标
width height 宽高只要是继承UIView的frame都可以这样设置
firstView.frame =
CGRect(x:10,y:100,width:300,height:45)
//能否响应点击事件
firstView.isUserInteractionEnabled =
true
//tag值
firstView.tag =
101
//边框的颜色
firstView.layer.borderColor =
UIColor.black.cgColor
//边框的宽度
firstView.layer.borderWidth =
2
//超过范围截取
firstView.layer.masksToBounds =
true
//边框的弧度
firstView.layer.cornerRadius =
5
//
self.view.addSubview(firstView)
//2.UILabel
//定义
let label =
UILabel()
label.isHidden =
true
//大小x、y坐标
width height 宽高
label.frame =
CGRect(x:50,y:60,width:200,height:50)
//背景颜色
label.backgroundColor =
UIColor.red
//字体颜色
label.textColor =
UIColor.white
//文字过长省略方式
label.lineBreakMode =
NSLineBreakMode.byClipping
//显示几行
label.numberOfLines =
1
//阴影
label.shadowColor =
UIColor.gray
//居中、居左
label.textAlignment =
NSTextAlignment.center
//透明度
label.alpha =
0.5
//字体粗心大小
label.font =
UIFont.boldSystemFont(ofSize:
20)
//高亮
label.isHighlighted =
true
label.highlightedTextColor =
UIColor.blue
//自适应
label.adjustsFontSizeToFitWidth =
true
self.view .addSubview(label)
//富文本:
let attribute =
NSMutableAttributedString(string:"李欢")
attribute.addAttribute(NSForegroundColorAttributeName, value:
UIColor.yellow, range:
NSMakeRange(0,
1))
label.attributedText = attribute
//UILabel本身也是继承与UIView、因此有touch
label.isUserInteractionEnabled =
true
//3.UIButton
let btn =
UIButton()
btn.isHidden =
false
btn.frame =
CGRect(x:10,y:200,width:300,height:44)
btn.backgroundColor =
UIColor.red
//btn的title highlighted、normal、等
btn.setTitle("按钮",
for: UIControlState.normal)
//颜色
btn.setTitleColor(UIColor.gray, for:
UIControlState.normal)
//图片
btn.setImage(UIImage.init(named:""),
for: UIControlState.normal)
//点击方法
btn.addTarget(self, action:#selector(click(_:)),
for:.touchUpInside)
btn.tag =
202
//以及继承UIView所具有的属性
self.view.addSubview(btw)
//点击方法
func click(_ btn:UIButton){
print(btn.tag)
}
相关文章推荐
- iOS基础——UI控件之UIView、UITextField、UILabel、UIColor、UIButton、UIImageView
- iOS学习笔记(七)——UI基础UIButton
- IOS学习笔记(三)之UIView的标签(UILabel)与按钮(UIButton)
- UI基础:UIButton.UIimage 分类: iOS学习-UI 2015-07-01 21:39 85人阅读 评论(0) 收藏
- 01【iOS总结】UIView、UILabel、UITextField、UIButton 、目标动作机制(+UIAlertView、UIAlertController)
- UI基础学习之(一):UIWindow、UIView的基本属性
- iOS学习——UI基础UIButton(七)
- iOS学习笔记(七)——UI基础UIButton
- iOS开发——UI基础-UIButton、UIImageView、UILabel的选择
- UI的开始————UIView,UILabel,UITextField,UIButton
- UI基础学习之(五):UIButton
- iOS学习笔记(七)——UI基础UIButton
- UI_iOS学习_UITextField_UILabel_UIButton
- iOS UI02.2_UIView,UILabel,UIButton,UItextfield归纳
- IOS学习笔记(五)——UI基础UIWindow、UIView
- python Tkinter学习笔记 基础UI控件 01
- 学习IOS开发UI篇--UIView\UIButton\UILabel\UIImageView\UITextField
- Swift UI学习之基础:UIButton,UILabel and UISlider
- UI基础学习之(二):UILabel
- UI基础之UIview,UILabel,UIWindow