swift基础学习UI(01)[UIView、UILabel、UIButton]

//控件的部分使用,以此类推其他属性

//1.UIView

let firstView = UIView()

firstView.isHidden = true

//背景

firstView.backgroundColor = UIColor.red;

//frame大小xy坐标 width height 宽高只要是继承UIViewframe都可以这样设置

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

//大小xy坐标 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,height:44)

btn.backgroundColor = UIColor.red

//btntitle highlightednormal、等

btn.setTitle("按钮",for: UIControlState.normal)

//颜色

btn.setTitleColor(UIColor.gray,for: UIControlState.normal)

//图片

btn.setimage(UIImage.init(named:""),0)">点击方法

btn.addTarget(self,action:#selector(click(_:)),for:.touchUpInside)

btn.tag = 202

//以及继承UIView所具有的属性

self.view.addSubview(btw)

//点击方法

func click(_ btn:UIButton){

print(btn.tag)

}

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...