UILabel的各种属性和方法
转自:http://liulu200888an.blog.163.com/blog/static/3498972320121214208542/
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 20.0, 180.0,50.0)];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(20.0, 80.0, 180.0, 50.0)];
UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(20.0, 140.0, 180.0, 50.0)];
UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(20.0, 200.0, 180.0, 50.0)];
//设置显示文字
label1.text = @"labelone";
label2.text = @"labeltwo";
label3.text = @"labelthree-labelthree-labelthree-labelthree-labelthree-labelthree";
label4.text = @"labelfour";
//设置文字颜色
label1.textColor = [UIColor redColor];
label2.textColor = [UIColor blueColor];
//设置字体:粗体,正常的是 SystemFontOfSize
label1.font = [UIFont boldSystemFontOfSize:30];
//设置文字位置,居中还是靠左靠右
label1.textAlignment = UITextAlignmentRight;
label2.textAlignment = UITextAlignmentCenter;
//设置字体大小适应label宽度
label4.adjustsFontSizeToFitWidth = YES;
//设置label的行数
label3.numberOfLines = 2;
//设置label的背景为透明
label2.backgroundColor = [UIColor clearColor];
//设置高亮
label4.highlighted = YES;
label4.highlightedTextColor = [UIColor orangeColor];
//设置阴影
label1.shadowColor = [UIColor redColor];
label1.shadowOffset = CGSizeMake(1.0,1.0);
//设置是否能与用户进行交互
label3.userInteractionEnabled = YES;
//设置label中的文字是否可变,默认值是YES
label3.enabled = NO;
//设置文字过长时的显示格式
label3.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode;
//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
label4.baselineAdjustment = UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
[self.view addSubview:label1];
[self.view addSubview:label2];
[self.view addSubview:label3];
[self.view addSubview:label4];
[label1 release];
[label2 release];
[label3 release];
[label4 release];
//点击label1时显示白色(是点击label1,不是点击label.Text)
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[label1 setTextColor:[UIColor whiteColor]];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[label1 setTextColor:[UIColor blackColor]];
UITouch *touch = [touches anyObject];
// CGPoint points = [touch locationInView:<#(UIView *)#>];
CGPoint points = [touch locationInView:label];
if (points.x >= label.frame.origin.x && points.y >= label.frame.origin.x && points.x <= label.frame.size.width && points.y <= label.frame.size.height)
{
// [delegate myLabel:self touchesWtihTag:self.tag];
}
}
最新文章
- C# 提交网页请求时出现如下错误: System.Net.WebException: 操作超时
- 利用GCC编译器生成动态链接库和静态链接库
- 算法训练 Hankson的趣味题
- 用facebook账号登陆到你的Magento网店
- Java List的深度克隆
- Oracle-decode函数
- [改善Java代码]非稳定排序推荐使用List
- 工程和界面—Webstorm入门指南 Webstorm中的工程-备
- 解读机器学习基础概念:VC维的来龙去脉 | 数盟
- ubuntu 设置静态IP之后不能上网。
- 一个人的旅行HDU 2066 floyd
- rsync源目录写法的一点小细节
- win10 更新系统更新补丁后无法启动处理办法
- asp.net中http接口的开发
- 【托业】【怪兽】TEST03
- DBNavigator1 按钮标题中文 提示中文
- centos6.5虚拟机无法访问外网解决办法
- 在Centos7上安装配置ss-libev Proxifier
- apo 简单参考
- access2003的使用
热门文章
- fatal error: iconv.h: No such file or directory
- Android Monkey使用
- [转]5 种使用 Python 代码轻松实现数据可视化的方法
- vue全局路由守卫beforeEach+token验证+node
- 使用DRF来快速实现API调用服务
- jenkins构建:通过testng.xml构建项目
- 【Eureka篇三】Eureka常用配置说明(7)
- vscode配置python环境-运行调试-windows环境
- 【Spring】Spring框架配置详情
- redis-5.0.5.tar.gz 安装