Skip to content

Instantly share code, notes, and snippets.

@leoShih
Last active July 3, 2017 11:44
Show Gist options
  • Save leoShih/593a3d4adfa5cbcfaee274a992ed387e to your computer and use it in GitHub Desktop.
Save leoShih/593a3d4adfa5cbcfaee274a992ed387e to your computer and use it in GitHub Desktop.
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