zoukankan      html  css  js  c++  java
  • 在UILabel内计算内容的大小

    //  UILabel+LM.h

    //
    //  UILabel+LM.h
    //  Test
    //
    //  Created by 李蒙 on 14-3-21.
    //  Copyright (c) 2014年 datangcloud. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface UILabel (LM)
    
    - (CGSize)contentSize;
    
    @end

    //  UILabel+LM.m

    //
    //  UILabel+LM.m
    //  Test
    //
    //  Created by 李蒙 on 14-3-21.
    //  Copyright (c) 2014年 datangcloud. All rights reserved.
    //
    
    #import "UILabel+LM.h"
    
    @implementation UILabel (LM)
    
    - (CGSize)contentSize
    {
        NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineBreakMode = self.lineBreakMode;
        paragraphStyle.alignment = self.textAlignment;
        
        NSDictionary * attributes = @{NSFontAttributeName : self.font,
                                      NSParagraphStyleAttributeName : paragraphStyle};
        
        CGSize contentSize = [self.text boundingRectWithSize:self.frame.size
                                                     options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                                  attributes:attributes
                                                     context:nil].size;
        return contentSize;
    }
    
    @end
  • 相关阅读:
    puttytray
    让程序同时输出到文件与屏幕(tee)
    R将文件转化为矩阵
    gnome3下gedit乱码的解决方案
    perl随机打乱数组
    gnome 3.6
    google earth 离线下载地址
    wget 使用技巧
    运行pindel注意事项
    获取当前行号与列号
  • 原文地址:https://www.cnblogs.com/limengdev/p/contentSize.html
Copyright © 2011-2022 走看看