【发布时间】:2018-05-04 05:17:54
【问题描述】:
我在集合视图中显示我的数据。我的应用支持所有方向、横向和纵向。我有带有标签的自定义 collectionViewCell 。我的单元格大小是
CGSize(width: self.view.frame.width / 3 - 40, height: self.view.frame.width / 3 - 40)`
因此,当我将设备旋转到横向模式时,它会增加单元格大小。
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
guard let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else {
return
}
flowLayout.invalidateLayout()
}
我在单元格中有一个标签
class ChannelViewCell: UICollectionViewCell {
let label : UILabel = {
let label = UILabel()
label.numberOfLines = 2
label.font = UIFont(name: "ProRegular", size: 13)
label.textAlignment = .center
label.textColor = UIColor.white
label.lineBreakMode = .byWordWrapping
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
addConstraintsWithFormat(format: "H:|-5-[v0]-5-|", views: label)
addConstraintsWithFormat(format: "V:|-5-[v0]-5-|", views: label)
}
}
我想在横向模式下将字体大小从 13 增加到 25。每次旋转设备时是否可以更新字体大小?
【问题讨论】:
标签: swift uilabel orientation font-size custom-cell