我正在尝试向@IBDesignable UICollectionViewCell
原型添加一个薄的彩色边框。在故事板中,我设置了layer.cornerRadius
,layer.masksToBounds
和layer.borderWidth
用户定义的属性,并且边框按预期显示。当设置layer.borderColor时,UICollectionViewCell边框消失
但是,如果我还设置自定义layer.borderColor
,整个边框,半径和口罩从故事板消失。在模拟器中,拐角半径(和掩模,大概)会出现,但边界不会。
我也尝试以编程方式设置它们,但作为this year-old, unanswered StackOverflow question显示,不工作,要么。
下面是该小区的代码,如要求:
@IBDesignable open class ReleaseSpineCell: UICollectionViewCell {
public var masterRelease: MasterRelease? {
didSet {
artistName = masterRelease?.artistName
title = masterRelease?.title
catalogNumber = "none"
}
}
@IBInspectable public var artistName: String? {
didSet {
artistLabel?.text = artistName
}
}
@IBInspectable public var title: String? {
didSet {
titleLabel?.text = title
}
}
@IBInspectable public var catalogNumber: String? {
didSet {
catalogLabel?.text = catalogNumber
}
}
@IBOutlet private weak var artistLabel: UILabel?
@IBOutlet private weak var titleLabel: UILabel?
@IBOutlet private weak var catalogLabel: UILabel?
}
和相关部分的UICollectionViewController
的dataSource
:
class CollectionModel: FetchedResultsCollectionModel {
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "spineCell", for: indexPath) as! ReleaseSpineCell
cell.masterRelease = fetchedResultsController?.fetchedObjects?[indexPath.row] as? MasterRelease
return cell
}
}
FetchedResultsCollectionModel
是一个自定义集合视图的数据源和委托这由NSFetchedResultsController
支持,而MasterRelease
是受管理的对象。我尽量保持这个东西尽可能简单。
您可以发布您的代码为您的自定义单元格? –
当然,但它只是一小撮'IBOutlet';没有有趣的代码。 – NRitH