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 = ; 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 = ; CGSize maxNameLabelSize = CGSizeMake(frame.size.width,);
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(, , self.view.frame.size.width-, ) text:_str font:[UIFont systemFontOfSize:.f] textColor:[UIColor redColor] backgroudColor:[UIColor clearColor] textAlignment:NSTextAlignmentLeft]];
UILabel+Create的更多相关文章
- 利用cocostudio库函数 实现左右滑动的背包栏UI (cocos2d-x 2.2.0)
.h #ifndef __COMMON_COMPONENTS__ #define __COMMON_COMPONENTS__ #include "cocos2d.h" #inclu ...
- NGUI学习笔记(一)UILabel介绍
来个前言: 作为一个U3D程序员,自然要写一写U3D相关的内容了.想来想去还是从UI开始搞起,可能这也是最直观同时也最重要的部分之一了.U3D自带的UI系统,也许略坑,也没有太多介绍的价值,那么从今天 ...
- UITextField和一个UILabel绑定 浅析
转载自:http://fengdeng.github.io/blog/2016/01/22/rxswift-dao-di-%5B%3F%5D-ge-uitextfieldshi-ru-he-he-%5 ...
- [Xcode 实际操作]四、常用控件-(5)UILabel文本标签自定义文字样式
目录:[Swift]Xcode实际操作 本文将演示给标签对象添加描边效果,在项目文件夹上,点击鼠标右键菜单, 选择[Create File]->[Cocoa Touch Class]->[ ...
- IOS 为UILabel添加长按复制功能
IOS 为UILabel添加长按复制功能 在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framewor ...
- IOS --关于粘贴板 ,剪切板 ,UILabel的复制
在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framework提供了几个类和协议方便我们在自己的应用程 ...
- 记一次tomcat线程创建异常调优:unable to create new native thread
测试在进行一次性能测试的时候发现并发300个请求时出现了下面的异常: HTTP Status 500 - Handler processing failed; nested exception is ...
- Could not create SSL connection through proxy serve-svn
RA layer request failedsvn: Unable to connect to a repository at URL xxxxxx 最后:Could not create SSL ...
- android 使用Tabhost 发生could not create tab content because could not find view with id 错误
使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误. 总结一下发生错误的原因,一般的 ...
随机推荐
- 在Servlet中使用spring注入的bean
package abu.csdn.servlet; import java.io.IOException; import javax.servlet.ServletContext; ...
- [Javascript] Regex: '$`', '$&', '$''
var input = "foobar"; var result = input.replace('bar', '$`'); // $`: replace 'bar' with e ...
- Python进阶之路---1.2python版本差异
Python2.*与python3.*版本差异 作为一个初学者,我们应该如何选择python的版本进行学习呢,这两个版本有什么区别呢,接下来让我们简单了解一下,以便我们后续的学习. Python版本差 ...
- C#基础之方法参数
params params 关键字可以指定在参数数目可变处采用参数的方法参数. 在方法声明中的 params 关键字之后不允许任何其他参数,并且在方法声明中只允许一个 params 关键字 publi ...
- Javascript基础Function
函数声明与表达式 function someFunc(){ alert("这是一个函数"); } var func=function(){ alert("函数表达式&qu ...
- 返回ipv 地址
//返回ipv 地址 public static string GetIP4Address() { string IP4Address = String.Empty; foreach (IPAddre ...
- oc随笔三:多态
多态使用总结: (1)没有继承就没有多态 (2)代码的体现:父类类型的指针指向子类对象 (3)好处:如果函数方法参数中使用的是父类类型,则可以传入父类和子类对象,而不用再去定义多个函数来和相应的类进行 ...
- javascript 概述及基础知识点(变量,常量,运算符,数据类型)
JavaScript概述 1.1 什么是JavaScript: javaScript(简称js),是一种基于对象和事件驱动并具有相对安全性的客户端脚本语言.同时也是一种广泛用于客户端Web开发的脚本语 ...
- 转载Eclipse中Maven WEB工程tomcat项目添加调试
转载地址: http://blog.csdn.net/free4294/article/details/38260581 一.建立一个maven WEB项目 1.file->new->o ...
- 转载:struts标签<s:date>的使用
转载网址:http://blog.sina.com.cn/s/blog_510fdc8b01010vjx.html s truts 标签 :<s:date/>作用:用来格式化显示日期的格式 ...