【发布时间】:2016-06-28 19:50:13
【问题描述】:
我在 UICollectionView 的 HeaderView 中有一个 UILabel。显示标签的文本,但有一些非常奇怪的格式问题。所有线条的边缘都非常锯齿,看起来很糟糕。
有人知道这个问题的解决方案吗?我以前从未见过这个问题。我的自定义视图代码如下:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
var reusableView = UICollectionReusableView();
if (kind == UICollectionElementKindSectionHeader) {
let header = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "SectionHeader", forIndexPath: indexPath)
let label = UILabel()
label.font = UIFont.systemFontOfSize(24.0)
switch indexPath.section {
case 0:
label.text = "UILabel with Weird Text Issues"
default:
label.text = ""
}
label.sizeToFit()
let leftInset = self.cv.contentInset.left
label.frame = CGRectMake(leftInset , header.frame.height-label.frame.height, label.frame.width, label.frame.height)
header.addSubview(label)
reusableView = header
}
return reusableView
}
【问题讨论】:
-
这是在真机还是模拟器上?有时,模拟器无法正确缩放,导致出现锯齿状线条或缺少一些像素。
-
这是真机截图。
标签: ios swift uicollectionview uilabel