从标签09.30获取时间,如果标签时间为08.12,我想将其作为hr = 09和min = 30,对应的值如hr = 08&min = 12,这可能吗?
答案 0 :(得分:2)
要获取hour
和minutes
,
let title = timeLbl.text?.split(separator: ".")
if let hourString = title?.first, let hour = Int(hourString) {
print(hourString)
print(hour)
}
if let minutesString = title?.last, let minutes = Int(minutesString) {
print(minutesString)
print(minutes)
}
要为title
设置两行label
,
let titleString = timeLbl.text?.replacingOccurrences(of: ".", with: "\n")
timeLbl?.numberOfLines = 0
timeLbl?.text = titleString
答案 1 :(得分:1)
let splitedStr = timeLbl.text?.split(separator: ".")
if let minStr = splitedStr?.first, let min = Int(minStr),
let secStr = splitedStr?.last, let sec = Int(secStr) {
var totalSec = (min * 60) + sec
totalSec += 1
timeLbl.text = String(format: "%02d.%02d", (totalSec/60),(totalSec%60) )
}