0

속성이있는 NSMutableString을 유지하는 데 문제가 있습니다. 각 UITableViewCell 누가 특성이 텍스트가있는 UITableView가 있습니다. 속성이 지정된 텍스트를 설정하는 것은 문제가되지 않지만 선택시 UITableViewCell의 특성은 손실됩니다.NSMutableAttributedString UILabel은 선택시 속성을 유지하지 않습니다.

NSMutableAttributedString *changesStyleString_h = [[NSMutableAttributedString alloc] initWithString:@"Attributes change!" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:20], NSForegroundColorAttributeName:[UIColor yellowColor]}]; 

[changesStyleString_h addAttributes:@{ NSUnderlineStyleAttributeName:@(1)} range:NSMakeRange(11, 6)]; 
cell.mainLabel.attributedText = changesStyleString 

내가 mainLabel도 UILabel의, 거기의 정의는 것을 지적 할 수 :이 특성을 설정 cellForRowAtIndexPath 내 코드입니다. 올바른 방향으로 도움을 주시면 대단히 감사하겠습니다!

답변

1

ENTIRE 문자열에 속성을 설정해야하거나 펑키 한 일이 발생한다는 것을 알았습니다.

NSString* string = @"1 - some string" 
NSMutableAttributedString* string = [[NSMutableAttributedString alloc] initWithString:string]; 
[string setAttributes:@{NSForegroundColorAttributeName: accent, NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.f]} range:NSMakeRange(0, 1)]; 

이렇게하면 셀을 강조 표시 할 때 이상한 동작이 발생할 수 있습니다. 내가 이런 짓을 할 때

그러나 :

[string setAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]} range:NSMakeRange(1, [labelTwo length] - 1)]; 

모든 것이 예상대로 작동하는 것 같았다.

희망 하시겠습니까?

관련 문제