【发布时间】:2017-01-12 12:18:29
【问题描述】:
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
}
}
我需要在下面的代码中声明一个图像以将其设置为部分背景,但它给了我一个错误。
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)
有什么帮助吗?
【问题讨论】:
标签: ios swift uiimageview uicollectionview