加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift计算字符串高度,宽度,size方法

发布时间:2020-12-14 02:22:55 所属栏目:百科 来源:网络整理
导读:计算字符串的高度 swift的原生方法名,基本跟OC一致 OC旧方法,用了会警告 CGSize size = [ self .message sizeWithFont:[ UIFont systemFontOfSize: 17 ] constrainedToSize:CGSizeMake( 200 , 9999 )]; OC新方法 CGSize size = [topicModel .content boundi

计算字符串的高度
swift的原生方法名,基本跟OC一致


OC旧方法,用了会警告

CGSize size = [self.message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(200,9999)];

OC新方法

CGSize size = [topicModel.content boundingRectWithSize:CGSizeMake(278,MAXFLOAT) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;

swift

boundingRectWithSize(size: CGSize,options: NSStringDrawingOptions,attributes: [NSObject : AnyObject]!,context: NSStringDrawingContext!) -> CGRect

var size = CGRect();
    var size2 = CGSize();
    size = string.boundingRectWithSize(size2,options: NSStringDrawingOptions.UsesFontLeading,attributes: nil,context: nil);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读