Swift,demo,ios8

Source: Internet
Author: User

Swift Exchange Group: 342581988, Welcome to increase.

Just wrote the little demo. It's still not too good. Please shoot the bricks!

Ability to replicate execution directly

Import Uikitclass Viewcontroller:uiviewcontroller {var l:uilabel! Override Func Viewdidload () {super.viewdidload ()//Do any additional setup after loading the view, typical                Ly from a nib. Let Labelrect = CGRectMake (140,75,50,50) var label = UILabel (frame:labelrect) Label.backgroundcolor = (UIC Olor.cyancolor ()) Self.view.addSubview (label) L = label var rect = CGRectMake (150,340        , 50,50) var UpButton = UIButton (frame:rect) upbutton.settitle ("Up", ForState:UIControlState.Normal) Upbutton.settitlecolor (Uicolor.bluecolor (), forState:UIControlState.Normal) Upbutton.tag = 1 Upbutton.setti Tlecolor (Uicolor.blackcolor (), forState:UIControlState.Highlighted) Self.view.addSubview (UpButton) UpButton.                AddTarget (self,action: "Moveclick:", forControlEvents:UIControlEvents.TouchUpInside); Rect = CGRectMake (150,420,50,50) var DownButton = UibuttOn (frame:rect) downbutton.settitle ("Down", ForState:UIControlState.Normal) Downbutton.settitlecolor (Uicolo R.bluecolor (), forState:UIControlState.Normal) Downbutton.tag = 2 Downbutton.settitlecolor (uicolor.blackcolo R (), forState:UIControlState.Highlighted) Self.view.addSubview (DownButton) downbutton.addtarget (self,action: "Moveclick:", forControlEvents:UIControlEvents.TouchUpInside) rect = CGRectMake (80,380,50,50) var lef TButton = UIButton (frame:rect) leftbutton.settitle ("left", ForState:UIControlState.Normal) Leftbutton.sett Itlecolor (Uicolor.bluecolor (), forState:UIControlState.Normal) Leftbutton.tag = 3 Leftbutton.settitlecolor (U Icolor.blackcolor (), forState:UIControlState.Highlighted) Self.view.addSubview (LeftButton) Leftbutton.addtar Get (self,action: "Moveclick:", forControlEvents:UIControlEvents.TouchUpInside) rect = CGRectMake (220,380,50,5 0) var Rigthbutton = UIButton (frame:rect) rigthbutton.settitle ("right", ForState:UIControlState.Normal) rigthbutton.settitl EColor (Uicolor.bluecolor (), forState:UIControlState.Normal) Rigthbutton.tag = 4 Rigthbutton.settitlecolor (UI Color.blackcolor (), forState:UIControlState.Highlighted) Self.view.addSubview (Rigthbutton) RIGTHBUTTON.ADDTA Rget (self,action: "Moveclick:", ForControlEvents:UIControlEvents.TouchUpInside)} override Func Didreceivememorywarning () {super.didreceivememorywarning ()//Dispose of any resources the can be recreate D.} func Moveclick (sender:uibutton!) {var centerpoint = L.center if Sender.tag = = 1{var newpoint = Cgpointmake (centerpoint.x , centerpoint.y-1) L.center = Newpoint}else if Sender.tag = = 2{var newpoint = Cgpointmake (c Enterpoint.x, centerpoint.y+1) L.center = Newpoint}else if Sender.tag = = 3{var newpoint = C GPointmake (centerpoint.x-1, centerpoint.y) L.center = Newpoint}else if Sender.tag = = 4{var n Ewpoint = Cgpointmake (centerpoint.x+1, centerpoint.y) L.center = Newpoint}}

Swift,demo,ios8

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.