2016-06-28 6 views
0

私はUICollectionViewのHeaderViewにUILabelを持っています。ラベルのテキストが表示されますが、いくつかの非常に奇妙な書式の問題があります。すべての線のエッジが非常にギザギザで、非常に悪いです。 enter image description hereUICollectionViewのUILabelでの不規則なテキストの問題

誰にも解決策がありますか?私は以前この問題を見たことがない。カスタムビューのための私のコードは以下の通りです:あなたはあなたのLabel何回も追加している

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 
} 
+0

これは実際のデバイスかシミュレータでですか?時には、物事がシミュレータ上で正しくスケールされないため、ギザギザの線や欠けているピクセルが生じることがあります。 –

+0

これは実際のデバイスからのスクリーンショットです。 – Kenneth

答えて

1

、あなたの問題は、あなたがあなたのUILabel前に追加し、新しいもの、

何か

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

等を除去する必要があるということです

私はこれがあなたに役立つことを願っています

関連する問題