创建UILabel
UILabelCreate.h
#import <UIKit/UIKit.h> @interface UILabelCreate : UILabel /**
* 创建UILabel 初始化不包含text
*
* @param frame frame
* @param font font
* @param textColor textColor
* @param backgroudColor backgroudColor
* @param textAlignment textAlignment
*/
- (void)createNormalLabel:(CGRect)frame font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment; /**
* 创建UILabel 初始化包含text
*
* @param frame frame
* @param text text
* @param font font
* @param textColor textColor
* @param backgroudColor backgroudColor
* @param textAlignment textAlignment
*/
- (void)createDefaultLabel:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment; /**
* 创建UILabel 初始化包含text(自增高)
*
* @param frame frame
* @param text text
* @param font font
* @param textColor textColor
* @param backgroudColor backgroudColor
* @param textAlignment textAlignment
*/
- (void)createLabelAdjustsFontSizeOfHigh:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment; ≈
* 设置Text并返回Label的高
*
* @param text text
* @param lableSizeWidth Label's Width
*
* @return Label's higt
*/
- (CGFloat)setTextWithLabelSizeHigh:(NSString *)text lableSizeWidth:(CGFloat)lableSizeWidth;
----------------------------------------------------------------------------------------------------
UILabelCreate.m
#define IOS7_BEFORE ([[[UIDevice currentDevice] systemVersion] floatValue] <7.0 ? YES : NO) #import "UILabelCreate.h" @implementation UILabelCreate - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} /*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/ - (void)createNormalLabel:(CGRect)frame font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment
{
[self setFrame:frame];
[self setFont:font];
[self setTextColor:textColor];
if (backgroudColor == nil) {
[self setBackgroundColor:[UIColor clearColor]];
}
else{
[self setBackgroundColor:backgroudColor];
}
[self setTextAlignment:textAlignment];
self.numberOfLines = ;
} - (void)createDefaultLabel:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment
{
[self setFrame:frame];
[self setText:text];
[self setFont:font];
[self setTextColor:textColor];
if (backgroudColor == nil) {
[self setBackgroundColor:[UIColor clearColor]];
}
else{
[self setBackgroundColor:backgroudColor];
}
[self setTextAlignment:textAlignment];
self.numberOfLines = ;
} - (void)createLabelAdjustsFontSizeOfHigh:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment
{
[self setText:text];
[self setFont:font];
[self setTextColor:textColor];
if (backgroudColor == nil) {
[self setBackgroundColor:[UIColor clearColor]];
}
else{
[self setBackgroundColor:backgroudColor];
}
[self setTextAlignment:textAlignment];
self.numberOfLines = ; CGSize maxNameLabelSize = CGSizeMake(frame.size.width,);
CGSize labelSize;
if (IOS7_BEFORE) {
labelSize = [text sizeWithFont:font
constrainedToSize:maxNameLabelSize
lineBreakMode:NSLineBreakByWordWrapping];
}
else{ labelSize = [text boundingRectWithSize:maxNameLabelSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:font}
context:nil].size; } [self setFrame:CGRectMake(frame.origin.x, frame.origin.y, labelSize.width, labelSize.height)];
} - (CGFloat)setTextWithLabelSizeHigh:(NSString *)text lableSizeWidth:(CGFloat)lableSizeWidth
{
[self setText:text]; CGSize maxNameLabelSize = CGSizeMake(lableSizeWidth,); CGSize labelSize;
if (IOS7_BEFORE) {
labelSize = [text sizeWithFont:self.font
constrainedToSize:maxNameLabelSize
lineBreakMode:NSLineBreakByWordWrapping];
}
else{ NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
self.font,NSFontAttributeName, nil]; labelSize = [text boundingRectWithSize:maxNameLabelSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil].size; }
return labelSize.height;
}
创建UILabel的更多相关文章
- NGUI学习笔记(一)UILabel介绍
来个前言: 作为一个U3D程序员,自然要写一写U3D相关的内容了.想来想去还是从UI开始搞起,可能这也是最直观同时也最重要的部分之一了.U3D自带的UI系统,也许略坑,也没有太多介绍的价值,那么从今天 ...
- UILabel UISwitch UISegmentedControl UIAlertView
基础小控件 /***************************************UIlabel*************************************/ UILabel ...
- iOS学习21之UILabel, UITextField, UIButton, UIImageView
1.UILabel 1> 概述 UILabel (标签): 是显示文本的控件.在App中 UILabel 是出现频率最高的控件 UILabel 是 UIView 子类,作为子类一般是为了扩充父类 ...
- 【iOS开展-50】使用它来创建一个新的类的实现代码包,因此,不自觉地练习简单MVC实验,附带动画
接下来说说代码封装最后一个个案. 最后一种情况看:[iOS开展-48]九宫格案例:自己主动布局.字典转模型运用.id和instancetype差别.xib反复视图运用及与nib关系 (1)代码封装的原 ...
- iOS UIlabel怎么加载html字符串 富文本的用法
要加载html字符串,用人说,直接用webView啊!但是,有时候我们只需要显示2行文字,如此少的内容却要在复杂的UI排版中加入一个占用资源较多的webview,得不偿失.这里要说的是,我们其实可以用 ...
- ios开发UI篇--UILabel
概述 UILabel类实现了一个只读文本视图.你可以使用这个类来画一个或多个静态文本.UILabel类支持既简单又复杂的样式标签文本,还可以控制外观,比如标签是否使用了一个影子或者处于高亮状态等等. ...
- 【Swift】UILabel的简单操作方法
@IBAction func buttonClick_LabelCtrl(sender: AnyObject) { //定义CGRect来初始化UILable var frame: CGRect = ...
- iOS开发基础控件--UILabel
UILabel 的常见属性和方法: //创建UIlabel对象 UILabel* label = [[UILabel alloc] initWithFrame:self.view.bounds]; / ...
- IOS开发学习笔记(1)-----UILabel 详解
1. [代码][C/C++]代码 //创建uilabelUILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, ...
随机推荐
- tooltips弹出框制作
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- java如何从方法返回多个值
本文介绍三个方法,使java方法返回多个值. 方法1:使用集合类 方法2:使用封装对象 方法3:使用引用传递 示例代码如下: import java.util.HashMap; import java ...
- MongoDB 操作手冊CRUD插入
插入操作 插入记录 1.插入一条记录 db.testData.insert({num:1,name:'a'}); 结果 WriteResult({ "nInserted" : 1 ...
- BNU10791:DOTA选人
DOTA(Defense of the Ancients)是一款很受欢迎的游戏.DOTA将10个游戏玩家分为两组,分别为天灾和近卫,推倒对方主基地的一方获得胜利.每个玩家可以选择一个英雄作为游戏中的角 ...
- 【技术文档】《算法设计与分析导论》R.C.T.Lee等·第7章 动态规划
由于种种原因(看这一章间隔的时间太长,弄不清动态规划.分治.递归是什么关系),导致这章内容看了三遍才基本看懂动态规划是什么.动态规划适合解决可分阶段的组合优化问题,但它又不同于贪心算法,动态规划所解决 ...
- FileShare文件读写锁解决“文件XXX正由另一进程使用,因此该进程无法访问此文件”(转)
开发过程中,我们往往需要大量与文件交互,读文件,写文件已成家常便饭,本地运行完美,但一上到投产环境,往往会出现很多令人措手不及的意外,或开发中的烦恼,因此,我对普通的C#文件操作做了一次总结,问题大部 ...
- poj1064 二分,注意精度!
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35269 Accepted: 7513 Des ...
- C语言结构体的字节对齐
Test Code: #include <iostream> #include <cstring> using namespace std; struct A{ int a; ...
- C#中弹出新窗口
1.在主窗体程序中定义对应别的窗体的对象 Form_a_class form1 = Form_a_class test_delegate(); 2.调用显示 form1.ShowDialog();
- hdu 5325 Crazy Bobo (树形dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Crazy Bobo Time Limit: 6000/3000 MS (Java ...