UICollectionView 的 UILabel 中的奇怪文本问题
Strange Text Issue in UILabel of a UICollectionView
我在 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
}
您多次添加 Label
,您的问题是,您需要在添加新 UILabel
之前删除
类似
for view in header.subviews {
view.removeFromSuperview()
}
希望对你有帮助
我在 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
}
您多次添加 Label
,您的问题是,您需要在添加新 UILabel
之前删除
类似
for view in header.subviews {
view.removeFromSuperview()
}
希望对你有帮助