Tôi có thêm một số UICollectionView
vào số UIViewController
và đã tạo một ô tùy chỉnh cho nó.Nội dung UICollectionViewCell kích thước sai khi tải lần đầu
Tôi đặt kích thước ô bằng phương pháp sizeForItemAtIndexPath
và đặt mỗi ô là UIScreen.mainScreen().bounds.width/2
ở cả chiều cao và chiều rộng. Vì vậy, về cơ bản, mỗi tế bào là một nửa màn hình rộng và chiều dài này cùng chiều cao.
Sau đó, tôi có một UIImageView
bên trong ô với mỗi cạnh được ghim vào cạnh tương đối của ô đó để chế độ xem hình ảnh lấp đầy ô. Tôi cũng có một số UILabel
được căn giữa theo chiều dọc và chiều ngang trong ô.
Tuy nhiên khi tải đầu tiên, ô có kích thước chính xác nhưng nội dung nhỏ hơn nhiều trong một hình vuông nhỏ ở trên cùng bên trái. (Xem trong hình bên dưới, tôi đã đặt màu nền của contentView là màu xanh lá cây và màu nền của imageView thành màu đỏ).
Sau đó, sau khi di chuyển xuống một chút (và tôi giả sử một tế bào tái sử dụng được dequeued) tất cả các tế bào cũng tốt (và duy trì tốt sau khi di chuyển sao lưu).
gì đang gây ra nội dung để không bị hạn chế đúng cách trên tải đầu tiên?
CẬP NHẬT
Một số mã từ UIViewController
tôi:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("PrevDrawCell", forIndexPath: indexPath) as? PrevDrawCell
if cell == nil {
cell = PrevDrawCell()
}
cell!.drawVC = self
cell!.imageShortCode = self.tempImageURLs[indexPath.row]
// Pull image (async) and set after download
cell!.setupImage()
cell!.contentView.backgroundColor = UIColor.greenColor()
cell!.coverView.backgroundColor = UIColor.redColor()
cell!.dateLabel.font = UIFont(name: "HelveticaNeue-Light", size: 26)
cell!.dateLabel.text = "\(self.tempImageURLs.count-indexPath.row)/9"
return cell!
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let size = UIScreen.mainScreen().bounds.width/2
return CGSize(width: size, height: size)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsetsZero
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
Hiển thị 'UIViewController' – Arsen
Bạn có nghĩa là hiển thị mã cho' UIViewController'? – myles
có, hiển thị mã số – Arsen