import UIKit
class ViewController: UIViewController {
@IBOutlet weak var la: UILabel!//注册便签1
@IBOutlet weak var la1: UILabel!//注册便签2
var i:Int = 0//设置变量i
@IBAction func bu(_ sender: Any) {//按钮活动
la.text = String(i)//便签1的内容显示为i的值
if i%3 == 0//便签2的颜色随i的变化而变化
{
la1.textColor=UIColor(red: 1, green: 0, blue: 0, alpha: 1) // 红
}
if i%3 == 1
{
la1.textColor=UIColor(red: 0, green: 1, blue: 0, alpha: 1) // 绿
}
if i%3 == 2
{
la1.textColor=UIColor(red: 0, green: 0, blue: 1, alpha: 1) // 蓝
}
i += 1//改变i的值,每点击一次i加一
}
override func viewDidLoad() {
super.viewDidLoad()
// 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.
}
}