【发布时间】:2020-01-18 16:01:39
【问题描述】:
我有一个通用的UILabel,我将从另一个控制器向其中传递数据。我想要它,这样标签将成为UISegmentedControl 的文本,但是我收到错误消息,即“实例成员'lessonLabel'不能用于类型LearnTopicHeaderView(我的班级是UICollectionReusableView)。
import UIKit
class LearnTopicHeaderView: UICollectionReusableView {
let lessonLabel = UILabel(text: "X Lessons", font: .systemFont(ofSize: 14))
let segmentedControl: UISegmentedControl = {
let sc = UISegmentedControl(items: ["Overview", lessonLabel, "Apply"]) // Here is the error.
sc.selectedSegmentIndex = 0
sc.layer.cornerRadius = 27
sc.addTarget(self, action: #selector(selectedIndex), for: .valueChanged)
return sc
}()
}
我不确定如何解决这个问题。
【问题讨论】:
标签: ios swift label uisegmentedcontrol