CollectionView单元格很小
我在项目中的CollectionView中,我在CollectionViewCell中添加了一些按钮和标签,并进行了所有自动划分,但是每当我运行项目时,CollectionViewCell都比计划的要小,或者在我的Xcode Storyboard上显示的解决方案,是否有其他解决方案?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "mainCell", for: indexPath as IndexPath) as! MainCollectionViewCell
cell.config(data: array1[indexPath.row])
return cell
}
class MainCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var postAuthor: UILabel!
@IBOutlet weak var postChannel: UILabel!
@IBOutlet weak var postDate: UILabel!
@IBOutlet weak var votesNumber: UILabel!
func config(data:PostModel){
self.profileImage.image = data.authorPhoto
self.postAuthor.text = data.authorName
self.postChannel.text = data.channelPosted
self.postDate.text = data.date
self.votesNumber.text = String(data.votesCount)
}
}
屏幕截图更好地理解
I've CollectionView in my project, I added some buttons and labels inside CollectionViewCell and did all the auto-layout, but anytime I run my project the CollectionViewCell is smaller than it is planned or appeared on my xcode storyboard, any solutions ?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "mainCell", for: indexPath as IndexPath) as! MainCollectionViewCell
cell.config(data: array1[indexPath.row])
return cell
}
class MainCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var postAuthor: UILabel!
@IBOutlet weak var postChannel: UILabel!
@IBOutlet weak var postDate: UILabel!
@IBOutlet weak var votesNumber: UILabel!
func config(data:PostModel){
self.profileImage.image = data.authorPhoto
self.postAuthor.text = data.authorName
self.postChannel.text = data.channelPosted
self.postDate.text = data.date
self.votesNumber.text = String(data.votesCount)
}
}
screenshots for better understanding
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论