@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