UILabel的详细使用
2012-11-19 13:32
183 查看
//设置阴影
[label setShadowColor:[UIColor blackColor]];
[label setShadowOffset:CGSizeMake(-2, 3)];
//设置是否能与用户进行交互
label.userInteractionEnabled = YES;
//设置label中的文字是否可变,默认值是YES
label.enabled = NO;
//设置高亮
label.highlighted = YES;
label.highlightedTextColor = [UIColor orangeColor];
//设置label的行数
label.numberOfLines = 2;
//设置文字位置
label.textAlignment = UITextAlignmentRight;
label.textAlignment = UITextAlignmentCenter;
//设置字体大小适应label宽度
label.adjustsFontSizeToFitWidth = YES;
//设置字体:粗体,正常的是 SystemFontOfSize
label.font = [UIFont boldSystemFontOfSize:20];
//设置显示文字
label.text = @"This is my label !";
//设置文字过长时的显示格式
label.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode;
//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
label.baselineAdjustment = UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
详细使用:
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(0,
0, 75, 40)]; //声明UIlbel并指定其位置和长宽
label.backgroundColor = [UIColorclearColor]; //设置label的背景色,这里设置为透明色。
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13]; //设置label的字体和字体大小。
label.transform = CGAffineTransformMakeRotation(0.1); //设置label的旋转角度
label.text = @“helloworld”; //设置label所显示的文本
label.textColor = [UIColorwhiteColor]; //设置文本的颜色
label.shadowColor = [UIColorcolorWithWhite:0.1falpha:0.8f]; //设置文本的阴影色彩和透明度。
label.shadowOffset = CGSizeMake(2.0f, 2.0f); //设置阴影的倾斜角度。
label.textAlignment = UITextAlignmentCenter; //设置文本在label中显示的位置,这里为居中。
//换行技巧:如下换行可实现多行显示,但要求label有足够的宽度。
label.lineBreakMode = UILineBreakModeWordWrap; //指定换行模式
label.numberOfLines = 2; //
指定label的行数
//lable的旋转
label.transform = CGAffineTransformMakeRotation(0.2); //设置label的旋转角度
[self.view addSubview:label]; //将label载入
label的美化和特效:
这里使用FXLabel来实现特殊效果,就是用FXLabel来实现的,但要加入FXLbal.h和FXLabel.m两个文件,具体代码如下。
FXLabel *label = [[FXLabelalloc] initWithFrame:CGRectMake(0,
0, 100, 30)];
label.backgroundColor = [UIColorclearColor];
label.font = [UIFontfontWithName:@"Helvetica-Bold"size:15];
label.text = [secondTitle objectAtIndex:i];
label.textColor = [UIColorgrayColor];
label.shadowColor = [UIColorcolorWithWhite:1.0falpha:0.8f];
label.shadowOffset = CGSizeMake(1.0f, 2.0f);
label.shadowBlur = 1.0f;
label.innerShadowColor = [UIColorcolorWithWhite:0.0falpha:0.8f];
label.innerShadowOffset = CGSizeMake(1.0f, 2.0f);
label.textAlignment = UITextAlignmentLeft;
[view addSubview:label];
其用法和UILabel相差不大,很好理解,代码大家可以直接调用,具体属性自己修改。效果如下:
实例demo:http://www.cocoachina.com/downloads/code/2011/1108/3463.html
theLabel.font=[UIFont systemFontOfSize:20.0];
theLabTwo.font=[UIFont boldSystemFontOfSize:20.0];
theLabel.font=[UIFont fontWithName:@"Helvetica" size:15];//带字体名字
//设置文字对齐方式
theLabel.textAlignment=UITextAlignmentCenter;
theLabTwo.textAlignment=UITextAlignmentLeft;
//设置高亮
theLabel.highlighted=YES;
theLabel.highlightedTextColor=[UIColor orangeColor];
theLabTwo.highlighted=YES;
theLabTwo.highlightedTextColor=[UIColor grayColor];
//设置是否能与用户进行交互
theLabel.userInteractionEnabled=YES;
theLabTwo.userInteractionEnabled=YES;
//设置字体大小适应label宽度
theLabel.adjustsFontSizeToFitWidth=YES;
theLabTwo.adjustsFontSizeToFitWidth=YES;
theLabel.adjustsFontSizeToFitWidth=YES;
theLabel.text=@"years,years,I love you!kjkljlkfjlskdfjlksdjflksdjflksdjflksdjflsjdflkdsf";
//设置label的行数
theLabel.numberOfLines=3;
theLabTwo.numberOfLines=2;
//设置label中的文字是否可变,默认值是YES
theLabel.enabled=YES;
theLabTwo.enabled=YES;
//设置阴影
theLabel.shadowColor=[UIColor grayColor];
theLabel.shadowOffset=CGSizeMake(1, 1);
//设置隐藏
theLabel.hidden=NO;
theLabTwo.hidden=NO;
//设置透明度:值越小越透明 0.0完成透明
theLabel.alpha=0.8;
theLabTwo.alpha=0.8;
//自动调整大小
theLabel.autoresizesSubviews=YES;
theLabTwo.autoresizesSubviews=YES;
//调节外框形状
theLabel.bounds=CGRectMake(0, 0, 200, 50);
theLabel.layer.cornerRadius=8;
//设置文字过长时的显示格式
// theLabTwo.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode;
if (theLabTwo.lineBreakMode == UILineBreakModeMiddleTruncation) {
theLabTwo.text=@"you,you,you,very tired,tired,tired,tiredtired,tired,tired,tired!";
}
//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
theLabTwo.baselineAdjustment = UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
//设置标号
theLabTwo.tag=101;
[label setShadowColor:[UIColor blackColor]];
[label setShadowOffset:CGSizeMake(-2, 3)];
//设置是否能与用户进行交互
label.userInteractionEnabled = YES;
//设置label中的文字是否可变,默认值是YES
label.enabled = NO;
//设置高亮
label.highlighted = YES;
label.highlightedTextColor = [UIColor orangeColor];
//设置label的行数
label.numberOfLines = 2;
//设置文字位置
label.textAlignment = UITextAlignmentRight;
label.textAlignment = UITextAlignmentCenter;
//设置字体大小适应label宽度
label.adjustsFontSizeToFitWidth = YES;
//设置字体:粗体,正常的是 SystemFontOfSize
label.font = [UIFont boldSystemFontOfSize:20];
//设置显示文字
label.text = @"This is my label !";
//设置文字过长时的显示格式
label.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode;
//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
label.baselineAdjustment = UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
详细使用:
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(0,
0, 75, 40)]; //声明UIlbel并指定其位置和长宽
label.backgroundColor = [UIColorclearColor]; //设置label的背景色,这里设置为透明色。
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13]; //设置label的字体和字体大小。
label.transform = CGAffineTransformMakeRotation(0.1); //设置label的旋转角度
label.text = @“helloworld”; //设置label所显示的文本
label.textColor = [UIColorwhiteColor]; //设置文本的颜色
label.shadowColor = [UIColorcolorWithWhite:0.1falpha:0.8f]; //设置文本的阴影色彩和透明度。
label.shadowOffset = CGSizeMake(2.0f, 2.0f); //设置阴影的倾斜角度。
label.textAlignment = UITextAlignmentCenter; //设置文本在label中显示的位置,这里为居中。
//换行技巧:如下换行可实现多行显示,但要求label有足够的宽度。
label.lineBreakMode = UILineBreakModeWordWrap; //指定换行模式
label.numberOfLines = 2; //
指定label的行数
//lable的旋转
label.transform = CGAffineTransformMakeRotation(0.2); //设置label的旋转角度
[self.view addSubview:label]; //将label载入
label的美化和特效:
这里使用FXLabel来实现特殊效果,就是用FXLabel来实现的,但要加入FXLbal.h和FXLabel.m两个文件,具体代码如下。
FXLabel *label = [[FXLabelalloc] initWithFrame:CGRectMake(0,
0, 100, 30)];
label.backgroundColor = [UIColorclearColor];
label.font = [UIFontfontWithName:@"Helvetica-Bold"size:15];
label.text = [secondTitle objectAtIndex:i];
label.textColor = [UIColorgrayColor];
label.shadowColor = [UIColorcolorWithWhite:1.0falpha:0.8f];
label.shadowOffset = CGSizeMake(1.0f, 2.0f);
label.shadowBlur = 1.0f;
label.innerShadowColor = [UIColorcolorWithWhite:0.0falpha:0.8f];
label.innerShadowOffset = CGSizeMake(1.0f, 2.0f);
label.textAlignment = UITextAlignmentLeft;
[view addSubview:label];
其用法和UILabel相差不大,很好理解,代码大家可以直接调用,具体属性自己修改。效果如下:
实例demo:http://www.cocoachina.com/downloads/code/2011/1108/3463.html
theLabel.font=[UIFont systemFontOfSize:20.0];
theLabTwo.font=[UIFont boldSystemFontOfSize:20.0];
theLabel.font=[UIFont fontWithName:@"Helvetica" size:15];//带字体名字
//设置文字对齐方式
theLabel.textAlignment=UITextAlignmentCenter;
theLabTwo.textAlignment=UITextAlignmentLeft;
//设置高亮
theLabel.highlighted=YES;
theLabel.highlightedTextColor=[UIColor orangeColor];
theLabTwo.highlighted=YES;
theLabTwo.highlightedTextColor=[UIColor grayColor];
//设置是否能与用户进行交互
theLabel.userInteractionEnabled=YES;
theLabTwo.userInteractionEnabled=YES;
//设置字体大小适应label宽度
theLabel.adjustsFontSizeToFitWidth=YES;
theLabTwo.adjustsFontSizeToFitWidth=YES;
theLabel.adjustsFontSizeToFitWidth=YES;
theLabel.text=@"years,years,I love you!kjkljlkfjlskdfjlksdjflksdjflksdjflksdjflsjdflkdsf";
//设置label的行数
theLabel.numberOfLines=3;
theLabTwo.numberOfLines=2;
//设置label中的文字是否可变,默认值是YES
theLabel.enabled=YES;
theLabTwo.enabled=YES;
//设置阴影
theLabel.shadowColor=[UIColor grayColor];
theLabel.shadowOffset=CGSizeMake(1, 1);
//设置隐藏
theLabel.hidden=NO;
theLabTwo.hidden=NO;
//设置透明度:值越小越透明 0.0完成透明
theLabel.alpha=0.8;
theLabTwo.alpha=0.8;
//自动调整大小
theLabel.autoresizesSubviews=YES;
theLabTwo.autoresizesSubviews=YES;
//调节外框形状
theLabel.bounds=CGRectMake(0, 0, 200, 50);
theLabel.layer.cornerRadius=8;
//设置文字过长时的显示格式
// theLabTwo.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode;
if (theLabTwo.lineBreakMode == UILineBreakModeMiddleTruncation) {
theLabTwo.text=@"you,you,you,very tired,tired,tired,tiredtired,tired,tired,tired!";
}
//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
theLabTwo.baselineAdjustment = UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
//设置标号
theLabTwo.tag=101;
相关文章推荐
- (转)UILabel的详细使用
- ios UILabel(label控件)的详细使用及特殊效果
- UILabel的详细使用及特殊效果
- Swift UIButton 和 UILabel 的详细解释和创建使用
- UILabel 相关使用方法间距、段落、文字颜色(详细)
- IOS--UILabel的使用方法详细
- ios UILabel 的详细使用及特殊效果
- ios UILabel(label控件)的详细使用及特殊效果
- 【UI】UILabel的详细使用
- UILabel的详细使用及特殊效果
- iOS--UILabel的使用方法详细
- 一步一步学ios UILabel(label控件)的详细使用及特殊效果(五5.6)
- UILabel的详细使用及特殊效果
- UILabel的详细使用及特殊效果
- 学习android之 Handler详细使用
- 各种语言及编译环境下使用winio的详细步骤
- Menu的详细使用
- vi的三种使用模式及详细用法
- mdadm详细使用手册
- 在JSP环境中配置使用fckeditor详细讲解