zoukankan      html  css  js  c++  java
  • UILabel+Create

    #import <UIKit/UIKit.h>
    
    @interface UILabel (Create)
    
    /**
     *  创建普通Label
     *
     *  @param frame          frame
     *  @param text           text
     *  @param font           font
     *  @param textColor      textColor
     *  @param backgroudColor backgroudColor
     *  @param textAlignment  textAlignment
     *
     *  @return UILabel
     */
    + (UILabel *)createLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor  textAlignment:(NSTextAlignment)textAlignment;
    
    /**
     *  创建自增高Label
     *
     *  @param frame          frame
     *  @param text           text
     *  @param font           font
     *  @param textColor      textColor
     *  @param backgroudColor backgroudColor
     *  @param textAlignment  textAlignment
     *
     *  @return UILabel
     */
    + (UILabel *)createAdjustsLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor  textAlignment:(NSTextAlignment)textAlignment;
    
    @end
    
    #import "UILabel+Create.h"
    
    @implementation UILabel (Create)
    
    + (UILabel *)createLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor  textAlignment:(NSTextAlignment)textAlignment
    {
        UILabel *label = [[UILabel alloc]initWithFrame:frame];
        label.text = text;
        [label setFont:font];
        [label setTextColor:textColor];
        if (backgroudColor == nil) {
            [label setBackgroundColor:[UIColor clearColor]];
        }
        else{
            [label setBackgroundColor:backgroudColor];
        }
        [label setTextAlignment:textAlignment];
        label.numberOfLines = 0;
        
        return  label;
    }
    
    + (UILabel *)createAdjustsLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor  textAlignment:(NSTextAlignment)textAlignment
    {
        UILabel *label = [[UILabel alloc]initWithFrame:frame];
        label.text = text;
        [label setFont:font];
        [label setTextColor:textColor];
        if (backgroudColor == nil) {
            [label setBackgroundColor:[UIColor clearColor]];
        }
        else{
            [label setBackgroundColor:backgroudColor];
        }
        [label setTextAlignment:textAlignment];
        label.numberOfLines = 0;
        
        CGSize maxNameLabelSize = CGSizeMake(frame.size.width,2000);
        CGSize labelSize;
        labelSize = [text boundingRectWithSize:maxNameLabelSize
                                       options:NSStringDrawingUsesLineFragmentOrigin
                                    attributes:@{NSFontAttributeName:font}
                                       context:nil].size;
        [label setFrame:CGRectMake(frame.origin.x, frame.origin.y, labelSize.width, labelSize.height)];
        
        return  label;
    }
    
    // 使用
    [self.view addSubview:[UILabel createLabelWithFrame:CGRectMake(10, 100, self.view.frame.size.width-20, 30) text:_str font:[UIFont systemFontOfSize:14.f] textColor:[UIColor redColor] backgroudColor:[UIColor clearColor] textAlignment:NSTextAlignmentLeft]];
  • 相关阅读:
    在调试asp.net程序时,提示windows窗体身份验证错误怎么办
    关于用css数字与汉字的垂直对其问题
    如何在存储过程中使用like操作符
    iframe的页面内容如何获取父页面的地址
    Visual Studio 2005常用插件搜罗(zz)
    如何通过javascript动态改变按钮的css属性值
    双十一数据库也疯狂,SQL Server 无法生成 FRunCM 线程,求解
    Oracle 连接玩我!ORA12514及ORA28547错误解决
    ASP.NET MVC Web API 学习笔记第一个Web API程序
    SQL Server数据库同步问题分享(三)创建订阅
  • 原文地址:https://www.cnblogs.com/joesen/p/4079380.html
Copyright © 2011-2022 走看看