내부에 단일 레이블이 있고 이상한 셀이있는 테이블보기가 있습니다. 나는이 하나의 라벨은 2 개 가지 색상으로 텍스트를 포함합니다 :UITableViewCell - 속성이있는 텍스트가있는 UILabel
let red = NSAttributedString(string: "Red color",
attributes:
[NSForegroundColorAttributeName: UIColor.redColor(),
NSFontAttributeName: normalFont])
let blue = NSAttributedString(string: "Blue color",
attributes:
[NSForegroundColorAttributeName: UIColor.blueColor(),
NSFontAttributeName: boldFont])
let attributedText = NSMutableAttributedString(attributedString: red)
attributedText.appendAttributedString(blue)
self.labelInformation.attributedText = attributedText
문제 : 텍스트가 모두 파란색 나는 이유를 이해할 수 없다. 내가 attributedText
을 인쇄 할 경우
내가 얻을 :
Red color
{
NSColor = "UIExtendedSRGBColorSpace 1 0 0 1";
NSFont = "<UICTFont: 0x104249d80> font-family: \"Open Sans\"; font-weight: normal; font-style: normal; font-size: 18.00pt";
}Blue color{
NSColor = "UIExtendedSRGBColorSpace 0 0 1 1";
NSFont = "<UICTFont: 0x10b51d7c0> font-family: \"Open Sans\"; font-weight: bold; font-style: normal; font-size: 20.00pt";
}
즉, 확인 같다!
보기에 적용된 동일한 코드가 적용되므로 문제는 테이블보기와 관련이 있어야합니다.
어떤 조언이 필요합니까?
업데이트
이 코드는 사용자 정의 셀보기의 방법 내부 :
컨트롤러에서class CustomViewCell: UITableViewCell {
func setup() {
// code above
}
}
:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CustomIdentifier") as! CustomTableViewCell
cell.setup()
return cell
}
스위프트 3.0은 꽤 잘 작동합니다. –
여기와 동일합니다. 놀이터에서 신속하게 작동합니다. – vikingosegundo
또한이 코드 조각을 게시 한 후에'self.labelInformation'과 관련된 코드가 있습니까 –