Tag: Class tar color get width Set
Import UIKit
class Viewcontroller: uiviewcontroller {
var greenview:UIView!
Override func viewdidload () {
Super. Viewdidload ()
Additional setup after loading the view, typically from a nib.
// create four system -type buttons to move the view left, right, up, down, respectively
//Create a button for the system type to move the view left
var leftbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton
// set button size and position
LeftButton. frame = CGRect(x:y: Max,width: +,height:)
// Set Title
LeftButton. Settitle ("←", forstate: uicontrolstate. Normal)
LeftButton. Settitle (" left ", forstate: uicontrolstate. Highlighted)
// Add Action
LeftButton. AddTarget (Self, Action:"didClicked1:", forControlEvents:uicontrolevents. Touchupinside)
// Display button
Self. View. Addsubview (LeftButton)
//Create a button for the system type to move the view right
var rightbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton
// set button size and position
Rightbutton. frame = CGRect(x:y: $,width: +,height:)
// Set Title
Rightbutton. Settitle ("→", forstate: uicontrolstate. Normal)
Rightbutton. Settitle (" right ", forstate: uicontrolstate. Highlighted)
// Add Action
Rightbutton. AddTarget (Self, Action:"DIDCLICKED2:", forControlEvents:uicontrolevents. Touchupinside)
// Display button
Self. View. Addsubview (Rightbutton)
//Create a button for the system type to move the view up
var upbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton
// set button size and position
UpButton. frame = CGRect(x:$, y:max, Width:+, Height:)
// Set Title
UpButton. Settitle ("↑", forstate: uicontrolstate. Normal)
UpButton. Settitle (" up ", forstate: uicontrolstate. Highlighted)
// Add Action
UpButton. AddTarget (Self, Action:"DIDCLICKED3:", forControlEvents:uicontrolevents. Touchupinside)
// Display button
Self. View. Addsubview (UpButton)
//Create a button for the system type to move the view down
var downbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton
// set button size and position
DownButton. frame = CGRect(x:, y: $, Width: +, height:)
// Set Title
DownButton. Settitle ("↓", forstate: uicontrolstate. Normal)
DownButton. Settitle (" down ", forstate: uicontrolstate. Highlighted)
// Add Action
DownButton. AddTarget (Self, Action:"DIDCLICKED4:", forControlEvents:uicontrolevents. Touchupinside)
// Display button
Self. View. Addsubview (DownButton)
// Create a view
var f1 = cgrect(x:y:, Width: +, Height: +)
Greenview = UIView(FRAME:F1)
// Define the background color of the view as Green
Greenview. backgroundcolor = uicolor. Greencolor ()
// Show View
Self. View. Addsubview (Greenview)
}
// Create method to implement view movement
func didClicked1 (sender: UIButton) {
var c = Greenview. Frame
if C.Origin. x = = 0
{
return
}
Else
{
var newframe = cgrect(x:c.Origin. X - ten, y:c.Origin. y, width:c.size. width, height:c.size. height)
Greenview. Frame = Newframe
}
}
func didClicked2 (sender: UIButton) {
var c = Greenview. Frame
if C.Origin. x = =
{
return
}
Else
{
var newframe = cgrect(x:c.Origin. X + ten, y:c.Origin. y, width:c.size. width, height:c.size. height)
Greenview. Frame = Newframe
}
}
func didClicked3 (sender: UIButton) {
var c = Greenview. Frame
if C.Origin. y = = 0
{
return
}
Else
{
var newframe = cgrect(x:c.Origin. x, Y:c.Origin. y - ten, width:c.size. width, height:c.size. height)
Greenview. Frame = Newframe
}
}
func didClicked4 (sender: UIButton) {
var c = Greenview. Frame
if C.Origin. y = = 380
{
return
}
Else
{
var newframe = cgrect(x:c.Origin. x, Y:c.Origin. y + ten, width:c.size. width, height:c.size. height)
Greenview. Frame = Newframe
}
}
Override func didreceivememorywarning () {
Super. Didreceivememorywarning()
//Dispose of any resources, can be recreated.
}
}