swift基础学习UI(01)[UIView、UILabel、UIButton]
来源:互联网 发布:淘宝销量排行榜2016 编辑:程序博客网 时间:2024/06/04 23:29
//控件的部分使用,以此类推其他属性
//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)
}
- swift基础学习UI(01)[UIView、UILabel、UIButton]
- Swift UI学习之基础:UIButton,UILabel and UISlider
- Swift UI学习之基础:UIButton,UILabel and UISlider
- Swift UI学习之基础:UIButton,UILabel and UISlider
- Swift - UIView,UILabel,UIButton,UIImageView
- **原创**零基础学ios**UI课程01***课堂笔记整理*UIView UILabel UIButton UITextField**
- iOS基础——UI控件之UIView、UITextField、UILabel、UIColor、UIButton、UIImageView
- UIView UILabel UITextField UIButton
- UIView,UILabel,UIButton,
- UI基础之UIview,UILabel,UIWindow
- UI学习笔记一 UIView和UILabel
- UI学习第一天UIView 和UILabel
- UIView,UILabel,UITextField,UIButton使用方法
- UIView UILabel UIButton知识整理
- UI基础知识 -- UIView UILabel
- UI - UIView、UILabel、AppDelegate
- swift学习笔记-UI篇之UILabel
- UI的开始————UIView,UILabel,UITextField,UIButton
- mysql数据库引擎常用面试总结
- 父类与子类之间的转换
- 怎样玩转千万级别的数据(表分区)
- Java格式化CST日期时间
- 贪吃蛇源码示例
- swift基础学习UI(01)[UIView、UILabel、UIButton]
- Java类加载机制、类加载器和反射机制-思维导图
- struts2之数据校验器
- ubuntu彻底卸载apache2、mysql、php(各版本通用)
- 【Android学习笔记】Webview图片自适应屏幕终极解决方案
- leetcode165. Compare Version Numbers
- javascript:typeof与instanceof区别
- 有源晶振和无源晶振的区别
- C# log4net无法输出日志