Created
July 6, 2017 13:41
-
-
Save leoShih/71a21413fd04e03eaacf853d92c49f6b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var BtnView: UIButton! | |
var index = 0 | |
var colors = | |
[UIColor(red: 1, green: 0, blue: 0, alpha: 1), | |
UIColor(red: 1, green: 127/255, blue: 0, alpha: 1), | |
UIColor(red: 1, green: 1, blue: 0, alpha: 1), | |
UIColor(red: 0, green: 1, blue: 0, alpha: 1), | |
UIColor(red: 0, green: 0, blue: 1, alpha: 1), | |
UIColor(red: 75/255, green: 0, blue: 130/255, alpha: 1), | |
UIColor(red: 148/255, green: 0, blue: 211/255, alpha: 1)] | |
@IBAction func Btn(_ sender: Any) { | |
view.backgroundColor = colors[index] | |
update() | |
if index == colors.count{ | |
index = 0 | |
} | |
} | |
func update(){ | |
index = index + 1 | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
index = Int(arc4random_uniform(7)) | |
view.backgroundColor = colors[index] //隨機產生array裡的顏色 | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment