-1

iOS アプリに共有機能を追加しています (iOS 5.0 までサポートする必要があります)。

次のコードは、IOS5 では適切に機能しているが、IOS 6 ではクラッシュしているラベルを打つことです。

CGContextStrokePath(c);でのクラッシュ。

CFIndex lineIndex = 0;
for (id line in lines) {        
    CGFloat ascent = 0.0f, descent = 0.0f, leading = 0.0f;
    CGFloat width = CTLineGetTypographicBounds((__bridge CTLineRef)line, &ascent, &descent, &leading) ;
    CGRect lineBounds = CGRectMake(0.0f, 0.0f, width, ascent + descent + leading) ;
    lineBounds.origin.x = origins[lineIndex].x;
    lineBounds.origin.y = origins[lineIndex].y;

    for (id glyphRun in (__bridge NSArray *)CTLineGetGlyphRuns((__bridge CTLineRef)line)) {
        NSDictionary *attributes = (__bridge NSDictionary *)CTRunGetAttributes((__bridge CTRunRef) glyphRun);
        BOOL strikeOut = [[attributes objectForKey:kTTTStrikeOutAttributeName] boolValue];
        NSInteger superscriptStyle = [[attributes objectForKey:(id)kCTSuperscriptAttributeName] integerValue];

        if (strikeOut) {
            CGRect runBounds = CGRectZero;
            CGFloat runAscent = 0.0f;
            CGFloat runDescent = 0.0f;

            runBounds.size.width = CTRunGetTypographicBounds((__bridge CTRunRef)glyphRun, CFRangeMake(0, 0), &runAscent, &runDescent, NULL);
            runBounds.size.height = runAscent + runDescent;

            CGFloat xOffset = CTLineGetOffsetForStringIndex((__bridge CTLineRef)line, CTRunGetStringRange((__bridge CTRunRef)glyphRun).location, NULL);
            runBounds.origin.x = origins[lineIndex].x + rect.origin.x + xOffset;
            runBounds.origin.y = origins[lineIndex].y + rect.origin.y;
            runBounds.origin.y -= runDescent;

            // Don't draw strikeout too far to the right
            if (CGRectGetWidth(runBounds) > CGRectGetWidth(lineBounds)) {
                runBounds.size.width = CGRectGetWidth(lineBounds);
            }

            switch (superscriptStyle) {
                case 1:
                    runBounds.origin.y -= runAscent * 0.47f;
                    break;
                case -1:
                    runBounds.origin.y += runAscent * 0.25f;
                    break;
                default:
                    break;
            }

            // Use text color, or default to black
            id color = [attributes objectForKey:(id)kCTForegroundColorAttributeName];

            if (color) {
                CGContextSetStrokeColorWithColor(c, (__bridge CGColorRef)color);
            } else {
                CGContextSetGrayStrokeColor(c, 0.0f, 1.0);
            }

            CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)self.font.fontName, self.font.pointSize, NULL);
            CGContextSetLineWidth(c, CTFontGetUnderlineThickness(font));
            CGFloat y = roundf(runBounds.origin.y + runBounds.size.height / 2.0f);
            CGContextMoveToPoint(c, runBounds.origin.x, y);
            CGContextAddLineToPoint(c, runBounds.origin.x + runBounds.size.width, y);

            CGContextStrokePath(c);
        }
    }

    lineIndex++;
}

}

4

1 に答える 1

4

TTTAttributedLabelのバグですこの問題をチェックしてください

うまくいけば、誰かがそれを解決し、解決策が得られるでしょう。解決するまで気をつけてください。

于 2013-04-10T11:09:41.963 に答える