-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 回答