【发布时间】:2017-11-01 08:48:37
【问题描述】:
我有一个CollectionViewController如下
class CollectionViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
var dogs = ["Dog1", "Dog2","Dog3"]
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
cell.testLabel.text = dogs[indexPath.row]
return cell
}
和CustomCell如下
class CustomCell: UICollectionViewCell {
@IBOutlet weak var testLabel: UILabel!
}
我喜欢将字体大小更改为上面的 18,但我得到的是我在情节提要中手动设置的字体。那么有没有办法可以在controller 中以编程方式更改字体,或者我需要在CustomCell 中更改它
附:刚刚发现会发生这种情况,当我在可用的设备尺寸上手动设置字体时,如果我删除了这些手动设备尺寸,它就可以工作。无论如何我可以覆盖它并同时拥有两者吗?
【问题讨论】:
-
替换 cell.testLabel.font = UIFont(name: "HelveticaNeue", size: 18) 为 cell.testLabel.font = UIFont.init(name: "HelveticaNeue", size: 18)跨度>
-
那行不通。
-
你能试试这个@IBOutlet weak var testLabel: UILabel! { didSet { testLabel.font = UIFont(name: "HelveticaNeue", size: 18) } }
-
我在 CustomCell 中试过了,就像你说的那样,它没有用。
-
您解决了问题还是仍然面临问题?
标签: ios swift xcode swift3 uicollectionview