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 错误. 总结一下发生错误的原因,一般的 ...
随机推荐
- jQuery限制文本框只能输入正整数
//限制键盘只能按数字键.小键盘数字键.退格键 $("#txtQty").keydown(function (e) { var code = parseInt(e.keyCode) ...
- C#冒泡泡算法
代码如下: static void Main(string[] args) { int[] arr = new int[] { 87, 85, 89, 84, ...
- php不会的点
1.DIRECTORY_SEPARATOR:DIRECTORY_SEPARATOR是一个显示系统分隔符的命令,DIRECTORY_SEPARATOR是PHP的内部常量,不需要任何定义与包含即可直接使用 ...
- Oracle instr 及 like
原文: http://www.cnblogs.com/crazyjava/archive/2012/10/31/2748202.html instr(string1,string2[,start_po ...
- WCF Service端Inspector
问题 在使用WCF的过程中,有时候需要在service端截取client和service之间的消息来做一些如写log,检查message是否合法的操作. 那么如何才能实现呢? 解决方案 使用WCF提供 ...
- 清除大文本中的html标签
public String clearHtmlText(String inputString) { if (StringUtils.isBlank(inputString)) { return &qu ...
- worklight 中添加时间控件
在我们使用worklight开发的过程中,由于文档的不开源和插件的缺少,总是自己琢磨很多东东,更有胜者 需要调用源代码实现某些不易实现的功能.在这里把实现的功能代码贴出来,如有不足之处还望指正! 实现 ...
- 帝国cms7.0整合百度编辑器ueditor教程
帝国cms7.0整合百度编辑器ueditor教程开始 1.根据自己使用的帝国cms版本编码下载对应的ueditor版本 下载地址 http://ueditor.baidu.com/website/do ...
- [FML]学习笔记三 Rademacher Complexity
该章节证明用到的不等式:Hoeffding不等式,McDiarmid不等式以及jensen不等式 Hoeffding's: McDiarmid不等式是Hoeffding不等式的一个推广,用f(S)代替 ...
- [linux] linux知识积累(不断更新中…)
一.vim知识 f(find)命令也可以用于移动,fx将找到光标后第一个为x的字符,3fd将找到第三个为d的字符. D 删除当前字符至行尾.D=d$ :split或new 打开一个新窗口,光标停在顶层 ...