创建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, ...
随机推荐
- C++——try、throw、catch实例学习程序
#include<iostream> #include<stdexcept> //exception/stdexcept/new/type_info头文件里都有定义的标准异常类 ...
- windows同一台电脑设置多个公钥与不同github帐号交互
1 生成公钥 1. 安装git,从C:\Documents and Settings\Administrator\.ssh\目录打开 "Git Bash":2. 键入命令:ssh- ...
- WCF入门教程系列四
一.概述 配置也是WCF编程中的主要组成部分.在 以往的.net应用程序中,我们会把DBConn和一些动态加载类及变量写在配置文件里.但WCF有所不同.他指定向客户端公开的服务,包括服务的地址. 服务 ...
- struts2 result的type属性
目前只使用过以下3种,都是直接跳转到另一个action chain: 写法:<result name="success" type="chain"> ...
- 初识CLR
眨眼间我已经实习了半年时间并且转正了,身份也正式从一个学生转变为一个职场人,这个博客自从开始实习以来就一直没有更新过= =没错,就是我懒癌晚期,不过不行!一切都要开始走向正轨,此博会继续见证我的成长, ...
- 小安,今天学会了MySQL中查询时间的方法哦
- angularjs directive 实例 详解
前面提到了angularjs的factory,service,provider,这个可以理解成php的model,这种model是不带html的,今天所说的directive,也可以理解成php的mo ...
- photoSlider-html5原生js移动开发轮播图-相册滑动插件
简单的移动端图片滑动切换浏览插件 分别引用css文件和js文件 如: <link rel="stylesheet" type="text/css" hre ...
- python之pandas模块
一.pandas模块是基于Numpy模块的,pandas的主要数据结构是Series和DadaFrame,下面引入这样的约定: from pandas import Series,DataFrame ...
- Django数据迁移
http://www.ziqiangxuetang.com/django/django-data-migration.html