我試圖改變你我的截圖,有一個綠色的背景,並說我們是開放的看到標籤。
我希望底部標籤變成紅色,並在上市開放時間過去後說「對不起,我們已關閉」,然後回到綠色並在正確的開放時間說「我們是開放的」。
我已經成功地將日期和時間導入頂部標籤,但我不確定底部標籤如何。
下面是代碼:
import UIKit
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
class FirstViewController: UIViewController {
var timer = Timer()
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var openStatusLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
FIRMessaging.messaging().subscribe(toTopic: "/topics/news")
self.timer = Timer.scheduledTimer(timeInterval: 1.0,
target: self,
selector: #selector(FirstViewController.tick),
userInfo: nil,
repeats: true)
}
@objc func tick() {
timeLabel.text = DateFormatter.localizedString(from: NSDate() as Date,
dateStyle: .medium,
timeStyle: .medium)
}
}
請發表您的代碼。 –
將代碼添加到原始帖子中。很多感謝 – Elfuthark
tick()函數需要首先確定是否打開或關閉...首先確定。 http://stackoverflow.com/questions/6112075/ios-compare-two-dates,一旦你這樣做,設置背景顏色和標籤內容應該很容易。 – CSmith