0
我的ViewController和里面UICollectionView,我试图UILable添加到UICollectionView编程:无法修改UICollectionView内的UILabel框架?
let Label: UILabel = {
let label = UILabel()
label.text = "Sample Text Here"
label.textAlignment = .center
label.textColor = UIColor(white: 0.4, alpha: 0.4)
label.font = UIFont.systemFont(ofSize: 20)
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
Label.translatesAutoresizingMaskIntoConstraints = false
Label.frame = CGRect(x: 0, y: 40, width: view.frame.width, height: 20)
collectionView.addSubview(Label)
}
,当我试图改变y值是相同
当我试图像这样添加它:view.addSubView(Label)
根本没有出现。
注:如果没有数据来填充细胞
不要将子视图添加到collectionView。创建UICollectionViewCell并将标签添加到单元格 – Bhanupriya
@Bhanupriya如果没有单元格填充,标签将出现 –