【发布时间】:2017-09-03 12:35:07
【问题描述】:
我遇到了一个我无法解决的问题。
我有一个struct,想更改每个集合视图中按钮的图像。我的文字/图像按计划工作。但是,当尝试更改图像按钮时,我很挣扎。有人可以帮我吗?
class CollectionViewContent{
var caption = ""
var mainImage: UIImage!
var userProfileImage : UIButton
init(caption: String, mainImage: UIImage!, userProfileImage : UIButton! )
{
self.description = description
self.mainImage = featuredImage
self.userProfileImage = postedUserProfileImage
}
static func showPosts() -> [Posts]
{
return [
Posts(description: "Sweet", mainImage: UIImage(named: "Image 1"), postedUserProfileImage:!),
Posts(description: "Awesome", mainImage: UIImage(named: "Image 2")!),
Posts(description: "WOW!", mainImage: UIImage(named: "Image 3")!
)
]
}
}
这是我的 collectionViewCell 类
class colViewContetCollectionViewCell: UICollectionViewCell {
var posts: Posts! {
didSet {
updateUI()
}
}
@IBOutlet weak var featuredImage: UIImageView!
@IBOutlet weak var postCaptionLabel: UILabel!
@IBOutlet weak var postedUserProfileImage: UIButton!
func updateUI() {
postCaptionLabel?.text! = posts.title
featuredImage?.image! = posts.featuredImage
postedUserProfileImage = posts.postedUserProfileImage
}
override func layoutSubviews() {
super.layoutSubviews()
self.layer.cornerRadius = 10.0
self.clipsToBounds = true
}
}
顺便说一句,我觉得这行代码不正确,我不太确定。
postedUserProfileImage = posts.postedUserProfileImage
【问题讨论】:
标签: ios uibutton uicollectionview uicollectionviewcell