zoukankan      html  css  js  c++  java
  • iOS系统弃用方法更新方法

    -boundingRectWithSize:options:attributes:context:用法

    - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakModeNS_DEPRECATED_IOS(2_0,7_0,"Use -boundingRectWithSize:options:attributes:context:");

    提示用:boundingRectWithSize:options:attributes:context:这个方法

    这个方法:

    - (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context

    几个参数:

    size:范围自己决定

    options :这是一个枚举类型

    typedefNS_ENUM(NSInteger, NSStringDrawingOptions) {

        NSStringDrawingTruncatesLastVisibleLine = 1 << 5, 

        NSStringDrawingUsesLineFragmentOrigin = 1 <<0,

        NSStringDrawingUsesFontLeading = 1 <<1, 

        NSStringDrawingUsesDeviceMetrics = 1 <<3, 

    } NS_ENUM_AVAILABLE_IOS(6_0);

    自己选一个适合的

    attributes:字典

    NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:20]};

    context:文本绘制的规范定义,一般为nil就可以。

    替换后:

    NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:20]};
    CGSize textSize = [@"字符串" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    drawInRect: withAttributes: 新方法的使用

    - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment NS_DEPRECATED_IOS(2_0, 7_0, "Use -drawInRect:withAttributes:"

    drawInRect: withAttributes:

    - (void)drawInRect:(CGRect)rect withAttributes:(nullable NSDictionary<NSString *, id> *)attrs NS_AVAILABLE(10_0, 7_0);

    之前的用法

    [self.placeHolder drawInRect:placeHolderRect
                                    withFont:self.font
                               lineBreakMode:NSLineBreakByTruncatingTail
                                   alignment:self.textAlignment];
    

    7.0以后

    NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
                textStyle.lineBreakMode = NSLineBreakByTruncatingTail;
                textStyle.alignment = self.textAlignment;
                UIFont *textFont = self.font;
                
                [self.placeHolder drawInRect:placeHolderRect withAttributes:@{NSFontAttributeName:textFont, NSParagraphStyleAttributeName:textStyle}];
    
    
    
  • 相关阅读:
    Unity3d TweenPosition.Begin()的使用浅析
    Unity3D 代理的使用及获取两个碰撞器的碰撞点
    Unity3D 调用GPS位置服务实现代码
    在控制台中输入msqyl一直报ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost'错误
    eclipse 提示错误The method of type must override a superclass method 的解决办法
    Linux高级命令
    Centos7安装及配置
    Linux基本命令
    多线程
    java总结
  • 原文地址:https://www.cnblogs.com/wlsxmhz/p/6140391.html
Copyright © 2011-2022 走看看