之間的標籤這是我的viewController掙扎在自定義類和視圖控制器
import UIKit
import SnapKit
class ViewController: UIViewController {
var numberInCircleView: NumberInCircleView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.setupViews()
}
func setupViews() {
self.numberInCircleView = NumberInCircleView(frame: .zero)
self.view.addSubview(self.numberInCircleView)
self.numberInCircleView.snp.makeConstraints { (make) in
make.leading.equalTo(20)
make.bottom.equalTo(-40)
make.width.equalTo(60)
make.height.equalTo(60)
}
self.numberInCircleView.numberLabel = 5
}
}
顯示數據下面是我的自定義類。
import Foundation
import UIKit
class NumberInCircleView: UIView {
var numberLabel: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
self.setupViews()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupViews()
}
func setupViews() {
self.numberLabel = UILabel(frame: .zero)
self.addSubview(self.numberLabel)
self.numberLabel.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
self.layer.cornerRadius = 30
self.backgroundColor = UIColor.red
self.layer.borderWidth = 1
self.layer.borderColor = UIColor.black.cgColor
self.numberLabel.text = ""
self.numberLabel.textAlignment = .center
self.numberLabel.textColor = UIColor.white
self.numberLabel.adjustsFontSizeToFitWidth = true
self.numberLabel.minimumScaleFactor = 0.5
}
這條線在我的ViewController
self.numberInCircleView.numberLabel = 5
應設置標籤爲5。我不知道我怎麼稱呼觀點之間做到這一點?您能否提一些建議?一些在線教程提供了我更多的信息,這將非常感謝。
你想幹什麼? –