Swift01-设置button

override func viewDidLoad() {
super.viewDidLoad()

//        var button:UIButton = UIButton(type:.ContactAdd)
        var button:UIButton = UIButton(type:.InfoDark);
//设置按钮位置和大小
 button.frame = CGRectMake(10,200,100,30)
//设置frame可以简化为
 var button2 = UIButton(frame:CGRectMake(10,250,100)) 
//按钮文字以及文字颜色的设置
button2.setTitle("button2",forState: UIControlState.normal)
        button2.setTitleColor(UIColor.blueColor(),forState: UIControlState.normal)
//添加button2到self.view
self.view.addSubview(button2);
button.setTitle("按钮",forState: UIControlState.normal);
    //设置按钮图片
button2.setimage(UIImage(named:"icon"),forState: UIControlState.normal)
self.view .addSubview(button);
    //设置背景颜色
//        button.backgroundColor = UIColor.redColor()
//设置button点击事件(这里跟oc有点区别 oc是@selector)
button2.addTarget(self,action: #selector(buttonpressed),forControlEvents: UIControlEvents.TouchUpInside)
}
//        不传递触摸对象(即点击的按钮)
func buttonpressed(){
        print("tapped")
    }

相关文章

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