首页 > 代码库 > iOS处理动态字符串长度(兼容6、7)

iOS处理动态字符串长度(兼容6、7)

NSString *saved = _name.text;

    CGSize size = CGSizeZero;

    if ([[[UIDevicecurrentDevice] systemVersion] floatValue] >=7.0) {

        size = [saved boundingRectWithSize:CGSizeMake(150, 70)options:NSStringDrawingUsesFontLeading |NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT(13)}context:nil].size;

    } else {

        size = [saved sizeWithFont:FONT(13)constrainedToSize:CGSizeMake(MAXFLOAT, 30)];

    }

    _name.width = size.width;

iOS处理动态字符串长度(兼容6、7)