【问题标题】:Strange Text Issue in UILabel of a UICollectionViewUICollectionView 的 UILabel 中的奇怪文本问题
【发布时间】: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


【解决方案1】:

您多次添加Label,您的问题是,您需要在添加新的之前删除您的UILabel

类似

    for view in header.subviews {
        view.removeFromSuperview()
    }

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-08
    • 2020-09-10
    • 2017-10-27
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多