zoukankan      html  css  js  c++  java
  • iOS 字符串的宽度和高度自适应

    //获取字符串的宽度
    -(float)widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
    {
        UIColor  *backgroundColor=[UIColor blackColor];
        UIFont *font=[UIFont boldSystemFontOfSize:fontSize];
        CGRect sizeToFit = [value boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{
                                                                                                                                                 NSForegroundColorAttributeName:backgroundColor,
                                                                                                                                                 NSFontAttributeName:font
                                                                                                                                                 } context:nil];
        
        return sizeToFit.size.width;
    }
    //获得字符串的高度
    -(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
    {
        UIColor  *backgroundColor=[UIColor blackColor];
        UIFont *font=[UIFont boldSystemFontOfSize:18.0];
        CGRect sizeToFit = [value boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{
                                           NSForegroundColorAttributeName:backgroundColor,
                                           NSFontAttributeName:font
                                           } context:nil];
        return sizeToFit.size.height;
    }
  • 相关阅读:
    通过mixins方法处理调取服务器时间
    记录个人对vuex的简单理解
    利用弹性布局实现垂直居中
    vue.set的适用方法
    深拷贝和浅拷贝的实现方法
    Maven安装步骤
    build tools
    Git
    Url和Uri的区别
    函数式编程语言
  • 原文地址:https://www.cnblogs.com/ceasar/p/6223473.html
Copyright © 2011-2022 走看看