0
好吧,我有一個集合視圖和我使用Xib文件創建的自定義單元格,以便可以在另一個視圖的另一個集合視圖中使用同一個單元格。在我cellForItemAtIndexPath我:CAGradientLayer沒有顯示?
let cell = collectionView.dequeueReusableCellWithReuseIdenitifier(cellIdentifier, forIndexPath: indexPath) as! StoriesCollectionViewCell
cell.setCell(arrArticles[indexPath.item])
return cell
,並在setCell FUNC我的自定義單元格類中:
func setCell(article : Article) {
self.articleImageView.alpha = 0.0
self.storyHeadline.text = article.headline
//set the background for the txtView to a gradient, from clear to white
let gradient = CAGradientLayer()
gradient.frame = txtView.frame
gradient.colors = [UIColor.clearColor().CGColor, UIColor.whiteColor().CGColor]
// gradient.startPoint = txtView.frame.origin
// gradient.endPoint = CGPointMake(txtView.frame.maxX, txtView.frame.maxY)
self.txtView.layer.insertSublayer(gradient, atIndex: 0)
//for testing purpose only, will be replaced by web service response
let dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .MediumStyle
dateFormatter.timeStyle = .NoStyle
self.storyHeadlineDate.text = dateFormatter.stringFromDate(article.date!)
manager.imageForArticle(article) { (image) in
self.articleImageView.image = image
UIView.animateWithDuration(1, animations: {
self.articleImageView.alpha = 1.0
})
}
self.layer.cornerRadius = 5.0
}
一切工作像我希望它比漸變背景色等。我也想知道是否有更好的委託方法來設置此漸變。txtView是一個UIView創建和鏈接從xib,順便說一句。
檢查梯度frame屬性,寬度,高度... –
是啊,我已經籤的是,在被插入子的時候,根據LLDB print語句是:width - 180.0,height - 35.0 ...這與txtView是相同的,並且都具有相同的x,y值 –