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 错误. 总结一下发生错误的原因,一般的 ...
随机推荐
- Linux备份
Eking<longpeisky@vip.qq.com> 19:35:17 增量备份是针对于上一次备份(无论是哪种备份):备份上一次备份后,所有发生变化的文件. (增量备份过程中,只备份 ...
- 把自己的程序打成jar包,让别人调用
我们写程序的时候往往需要把自己的程序打包成jar包,给第三方调用.Eclipse让我们非常方便的可以导出jar包.但是当程序里需要用到res里的资源时,往往就会出现问题.因为统自动生成的R类如果被打 ...
- android避免service被杀
1.在service中重写下面的方法,这个方法有三个返回值, START_STICKY是service被kill掉后自动重写创建@Override public int onStartComma ...
- ASE中的主要数据库
Adaptive Server包括多种类型数据库: 必需数据库. “附加功能”数据库 .例子数据库 .应用数据库 1.必需数据库 master 数据库包含系统表,这些系统表中存储的数据被用来管理,有 ...
- .NET基础拾遗(5)反射2
本篇是学习反射的一个应用小场景而做的学习笔记,主要是一个小的总结,并对各个步骤的记录,以便将来回顾. 一.基础框架-敏捷基础版本 这里假定我们要开发一个记事本,选择Windows Form技术开发,界 ...
- C#调用Java代码
c#直接调用java代码,需要ikvmbin-0.44.0.5.zip.下载地址: http://pan.baidu.com/share/link?shareid=3996679697&uk= ...
- iPhoneKeyboard
iPhoneKeyboard.Open static function Open (text : string, keyboardType : iPhoneKeyboardType = iPhoneK ...
- hdu 素数环
算法:搜索 题意:相邻的两个数之和是素数,别忘了最后一个,和第一个 Problem Description A ring is compose of n circles as shown in dia ...
- jquery select三级联动
需求:对地区进行选择,选择相应的省,就会出现相应范围的市,然后出现相应的范围的县区:如果县不存在,就不现实,自我要求是自己写个简单的插件,方便以后调用: 逻辑:1.通过div的类名来获取,其下的sel ...
- clearInterval()与setInterval()的应用
1.setInterval()按照一定的周期调用函数2.clearInterval()取消setInterval()的周期调用 例如:图片轮播中的clearInterval()与setInterval ...