2017-01-12 9 views
0
class MDCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes 
{ 
    var color: UIColor = UIColor.whiteColor() 
    var image : UIImageView! 

    override func copyWithZone(zone: NSZone) -> AnyObject 
    { 
     let newAttributes: MDCollectionViewLayoutAttributes = super.copyWithZone(zone) as! MDCollectionViewLayoutAttributes 
     newAttributes.color = self.color.copyWithZone(zone) as! UIColor 
     newAttributes.image = UIImageView(frame:newAttributes.bounds) 
     newAttributes.image.image = UIImage(named:"Appetizer.png") 

     newAttributes.image = self.image.copyWithZone(zone) as! UIImageView// this is giving me an error 
     return newAttributes 
    } 
} 

次のコードでセクション・バックグラウンドとして使用するにはイメージを宣言する必要がありますが、エラーが発生します。error:静的メンバーcopyWithZoneは、UIImageView型のインスタンスでは使用できません。

override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? 
{ 
    let attributes = super.layoutAttributesForElementsInRect(rect) 
    var allAttributes = [UICollectionViewLayoutAttributes]() 

    if let attributes = attributes 
    { 

     for attr in attributes 
     { 
      if (attr.representedElementCategory == UICollectionElementCategory.Cell && attr.frame.origin.x == self.sectionInset.left) 
      { 
            let decorationAttributes = SBCollectionViewLayoutAttributes(forDecorationViewOfKind: "sectionBackground", withIndexPath: attr.indexPath) 

       // decorationAttributes.color = UIColor.brownColor().colorWithAlphaComponent(1) 

ヘルプが必要ですか?

答えて

0

UIImageViewはNSCopyingプロトコルに準拠していないため、copyWithZoneが機能しません。 NSCopying準拠を実装するUIImageViewまたはそのサブクラスの拡張を作成できます。

+0

ありますか?または例のための任意のリンク? –

関連する問題