zoukankan      html  css  js  c++  java
  • 获取UILabel宽度的方法

    /**

     获取 label 的宽度

     

     @param fontType 0:正常  1:粗体  2:斜体

     */

    - (CGFloat)getLabelWidth:(NSString *)text fontSize:(CGFloat)fontSize type:(NSInteger)fontType

    {

        UILabel *label = [[UILabel alloc] init];

        label.text = text;

        switch (fontType)

        {

            case 0:

                label.font = [[PTVConfig instance] normalFont:fontSize];

                break;

            case 1:

                label.font = [[PTVConfig instance] boldFont:fontSize];

                break;

            default:

                label.font = [[PTVConfig instance] italicFont:fontSize];

                break;

        }

     

        CGRect bound = [label textRectForBounds:CGRectMake(0, 0, MAXFLOAT, fontSize * 1.5) limitedToNumberOfLines:1];

        CGFloat width = bound.size.width;

        return width;

    }

  • 相关阅读:
    js阻止事件冒泡和标签默认行为
    Sql server不同数据类型间拼接(+)
    win7 激活相关
    查找算法
    算法基础
    requests库使用
    python urllib和urllib3包使用
    爬虫工具fiddle在firefox浏览器中的使用
    爬虫抓包工具Fiddle设置
    爬虫抓包工具Charles设置
  • 原文地址:https://www.cnblogs.com/lz465350/p/5622053.html
Copyright © 2011-2022 走看看