我正在嘗試向@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