2012-09-21 3 views
13

그러나, 나는 오류 조금이라도 문제가 있으면 설정된 메시지가 출시 된 개체로 전송되고있는 것으로 보입니다. 디버거를 사용하여, 나는 CTFontRef 인 것으로 보이는 po'd 0x200020e0을가집니다.(NSCFType 세트) 아이폰 OS에서 인식 할 수없는 선택 (6) 내가 아이폰 OS 6에서 아이폰 OS 5에서 잘 작동 큰 TTTAttributedLabel (<a href="https://github.com/mattt/TTTAttributedLabel" rel="noreferrer">https://github.com/mattt/TTTAttributedLabel</a>)를 사용하고

https://github.com/mattt/TTTAttributedLabel

그 코드 : 여기에 사용 예에서와 같이

[label setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) { 
    NSRange boldRange = [[mutableAttributedString string] rangeOfString:title options:NSCaseInsensitiveSearch]; 
    NSRange strikeRange = [[mutableAttributedString string] rangeOfString:@"sit amet" options:NSCaseInsensitiveSearch]; 


    UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:20]; 

    CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL); 

    if (font) { 
     [mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:boldRange]; 
     [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(__bridge id)font range:boldRange]; 
     CFRelease(font); 
    } 

    return mutableAttributedString; 
}]; 

:

po 0x200020e0 
(int) $0 = 536879328 CTFont <name: .HelveticaNeueUI-Bold, size: 20.000000, matrix: 0x0> 
CTFontDescriptor <attributes: <CFBasicHash 0x20001900 [0x3c2a4100]>{type = mutable dict, count = 1, 
entries => 
1 : <CFString 0x3be2a768 [0x3c2a4100]>{contents = "NSFontNameAttribute"} = <CFString 0x3c292c14 [0x3c2a4100]>{contents = ".HelveticaNeueUI-Bold"} 

은}

이것은 TTTAttributedLabel을 설정하는 코드에 직선 저를 주도 ARCified가 아니므로 브리지 된 캐스트를 추가했습니다 (위 참조). 나는 그 곳곳에 머무르려고했으나 CTFontRef가 너무 일찍 릴리스되는 이슈 (그럴 것으로 보입니다)를 해결하지 못하는 것 같습니다 (제 생각에는 - 다른 제안이 환영합니다).

이 문제를 해결하는 방법에 대한 아이디어와 iOS 6 시뮬레이터에서이 작업을 수행하는 이유는 무엇입니까? 미리 감사드립니다.

답변

4

테스트를하지 않음 NSMutableAttributedString에 속성을 추가하는 범위. 범위를 고정하면 충돌이 해결되었습니다!

EDIT : 속성 사전에 UITextAttributeFont를 사용하여 관리 할 수도 있습니다. iOS 7에서는 더 이상 사용되지 않을 것으로 보이지만 이제는 신비하게 충돌합니다. 대체는 NSForegroundColorAttributeName입니다.

2

UILabel myLabel이있는 이 있고 myLabel.attributedText = NSMutableAttributedString 일 때 동일한 오류가 발생했습니다.

https://github.com/AliSoftware/OHAttributedLabel

가 선언보십시오 : 대신 UILabel의의

@property (nonatomic, strong) IBOutlet OHAttributedLabel *myLabel;

오류를 해결합니다.

7

은 대체 :

CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL); 

로 :

UIFont *font = [UIFont fontWithName:boldSystemFont.fontName size:boldSystemFont.pointSize]; 

나를 위해 iOS6의에서 문제가 해결되었습니다.

[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor blueColor].CGColor range:boldRange]; 
1

내가 나쁜를 사용했는데이 오류를 얻을 수 있었다 :

[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(__bridge id)font range:boldRange]; 

읽고해야 - 그냥 바보 같은 실수 결국 아이폰 OS (5)

+0

죄송합니다, 거기에 편집이별로 의미가 없다는 것을 알았습니다. 어떤 키를 의미하는지 기억이 나지 않지만 상황에 따라 알아낼 수 있습니다. 기본적으로 사용되지 않는 키는 사용하지 마십시오! – CMash