Use of Swift-uiview

Source: Internet
Author: User

viewcontroller.swift//Swiftui program -07import uikitclass Viewcontroller:uiviewcontroller {var clickCount:Int = 0;/ /clickcount is not declared as an int var mylabel:uilabel? Declare a global variable? Indicates that the initial value is null override func Viewdidload () {super.viewdidload ()//is a base class where some must be written keyword let color = uicolor.redcol        or ();//Create a Red object//color is a constant let Color1 = Uicolor.graycolor ();                Self.view.backgroundColor = Color1; Super represents the parent class//3. Create a controller//change the back color to red//Do any additional setup after loading the view, T           Ypically from a nib.  Adding a Uilabel//cgrect to the interface is equivalent to the interval coordinates of the previous CGRectMake//frame in the parent view//Here is the label content, and the tag in OC is taken using let Rect =        CGRect (x:0,y:100,width:320,height:44);        MyLabel = UILabel (Frame:rect); mylabel!.        Text = "Baidu";//indicates empty also can go to create//Add MyLabel object to Self.view object Self.view.addSubview (mylabel!); mylabel!.                        BackgroundColor = Uicolor.redcolor (); Create a UIButton       var MyButton = UIButton (Frame:cgrect (x:100,y:200,width:100,height:44));        Mybutton.backgroundcolor = Uicolor.purplecolor (); Set Text To button//settitle The first parameter does not need to be labeled, the second parameter forstate is the label mybutton.settitle ("Click Me", Forstate:.        Normal); Set a text To button//to Mybuttom Add Click event Mybutton.addtarget (Self, Action: "ClickMe:", forControlEvents:.        Touchupinside);    Self.view.addSubview (MyButton);        }//defines a click event function func clickme (Sender:uibutton) {clickcount + = 1;        /** * \ (put variable or expression here) */println ("click \ (Clickcount)"); mylabel!.    Text = "Baidu \ (Clickcount)"; } override func Didreceivememorywarning () {super.didreceivememorywarning ()//Dispose of any resources t    Hat can be recreated. }}

Use of Swift-uiview

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.