简体   繁体   中英

Xcode - changing the number of labels

Hello I am new to coding and in seek of help. Lately i've been trying to make it so in a label if it get's to a certain number in my case 8 it resets back to 0.

let label = UILabel()
var count: Int = 0 {
    didSet {
        if count == 8 {
            count = 0
        }
        label.text = "\(count)"
    }
}

all you need to do is to increment the count where you need, everything else is taking care of by the didSet - reseting count and updating label text.

increment your count as:

count += 1 // or the value you need

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM