美文网首页iOS 开发 iOS开发好文
MRC改ARC,顺便优化一些系统废弃的API

MRC改ARC,顺便优化一些系统废弃的API

作者: 大灰灰iOS | 来源:发表于2015-03-24 21:58 被阅读197次

    drawInRect方法

    //iOS8废弃
    - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment
    </pre>
    <pre>  //iOS7以后
    NSMutableParagraphStyle *titleStyle = [[[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]autorelease];
    titleStyle.lineBreakMode = NSLineBreakByTruncatingTail;
    titleStyle.alignment = NSTextAlignmentLeft;
    NSDictionary *titleAttribute = @{
                                    NSFontAttributeName:titleFont,
                                    NSParagraphStyleAttributeName:titleStyle
                                    };
    [_title drawInRect:r withAttributes:titleAttribute];
    CGSize s = [_title sizeWithAttributes:titleAttribute];
    

    sizeWithFont方法

    //iOS7以后
    NSDictionary *attribute = @{NSFontAttributeName:withFont};
        return [text boundingRectWithSize:CGSizeMake(width, FLT_MAX) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    
    //iOS8废弃
    [text sizeWithFont:withFont
     constrainedToSize:CGSizeMake(width, FLT_MAX) 
         lineBreakMode:lineBreakMode]
    

    简书已经弃用,欢迎移步我的小专栏:
    https://xiaozhuanlan.com/dahuihuiiOS

    相关文章

      网友评论

        本文标题:MRC改ARC,顺便优化一些系统废弃的API

        本文链接:https://www.haomeiwen.com/subject/dlugxttx.html