Last active
July 3, 2017 11:44
-
-
Save leoShih/593a3d4adfa5cbcfaee274a992ed387e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
let colors = [UIColor.black, UIColor.blue] | |
var index = 0 | |
@IBOutlet weak var btnView: UIButton! | |
@IBAction func btn(_ sender: Any){ | |
btnView.backgroundColor = colors[index] | |
update() | |
if index == colors.count | |
{ | |
index = 0 | |
} | |
} | |
func update() | |
{ | |
index = index + 1 | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
btnView.backgroundColor = .blue //進入畫面就顯示藍色 | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment