swift -UIView的使用

swift -UIView的使用,第1张

概述//// ViewController.swift// SwiftUI程序-07import UIKitclass ViewController: UIViewController { var clickCount:Int = 0;//clickCount 并没有声明为int var myLabel:UILabel? //申明一个全局变量?表示初始值为空
////  VIEwController.swift//  SwiftUI程序-07import UIKitclass VIEwController: UIVIEwController {    var clickCount:Int = 0;//clickCount 并没有声明为int    var myLabel:UILabel? //申明一个全局变量?表示初始值为空    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()//是基类当中有的 必须写个关键字        let color = UIcolor.redcolor();//创建一个红色对象        //color 是一个常量        let color1 = UIcolor.graycolor();        self.vIEw.backgroundcolor = color1;                //super 表示父类        //3.创建一个Controller             //把背静颜色改为红色        // Do any additional setup after loading the vIEw,typically from a nib.           //在界面上加个UILabel        //CGRect 相当于之前的CGRectMake        //frame 在父视图中的区间坐标        //这里是标签内容,将oc 中的标签来拿使用        let rect = CGRect(x:0,y:100,wIDth:320,height:44);        myLabel = UILabel(frame: rect);        myLabel!.text = "百度";//表示为空也可以去创建        //把myLabel 对象加入到self.vIEw 对象上        self.vIEw.addSubvIEw(myLabel!);        myLabel!.backgroundcolor = UIcolor.redcolor();                        //创建一个UIbutton        var mybutton = UIbutton(frame: CGRect(x:100,y:200,wIDth:100,height:44));                mybutton.backgroundcolor = UIcolor.purplecolor();        //给button 设置文字        //setTitle 第一个参数不需要跟标签,第二个参数forstate 是标签        mybutton.setTitle("点击我",forState:.normal);        //给button 设置一个文字                //给mybuttom 增加点击事件         mybutton.addTarget(self,action: "clickMe:",forControlEvents:.touchUpInsIDe);        self.vIEw.addSubvIEw(mybutton);    }//定义一个点击事件的函数        func clickMe(sender:UIbutton){        clickCount += 1;        /**        *  \(这里放变量或者表达式)        */        println("click \(clickCount)");        myLabel!.text = "百度\(clickCount)";    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}
总结

以上是内存溢出为你收集整理的swift -UIView的使用全部内容,希望文章能够帮你解决swift -UIView的使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1085495.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存