UILable用法
2016-02-18 22:22
399 查看
原文:http://blog.sina.com.cn/s/blog_bf9843bf0101f7z7.html(1)初始化UILabel *aLabel=[[UILabel alloc]initWithFrame:CGRectMake(50, 50, 100, 50)];(2)文字内容//位置默认是靠左的[aLabel setText:@"hello"];//设置字体颜色aLabel.textColor=[UIColor blueColor];aLabel.textColor=[UIColor redColor];//设置字体大小aLabel.font=[UIFont systemFontOfSize:12.4];//修改字体的字体和大小aLabel.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:36.0];//设置背景颜色aLabel.backgroundColor=[UIColor redColor];//清空背景颜色aLabel.backgroundColor=[UIColor clearColor];//设置对齐方式aLabel.textAlignment = UITextAlignmentLeft;//文字靠左aLabel.textAlignment = UITextAlignmentCenter;//文字居中aLabel.textAlignment = UITextAlignmentRight;//文字靠右//设置字体大小是否适应label宽度aLabel.adjustsFontSizeToFitWidth=YES;//是YES时,这个属性就来控制文本基线的行为在定义里面允许有以下格式显示:
typedef enum {
UIBaselineAdjustmentAlignBaselines,
//默认值文本最上端与label中间线对齐[/code]
UIBaselineAdjustmentAlignCenters,
//text中间与label中间线对齐
UIBaselineAdjustmentNone, //text最低端与label中间线对齐
} UIBaselineAdjustment;//设置是否是高亮aLabel.highlighted=YES;//高亮颜色aLabel.highlightedTextColor=[UIColor redColor];//设置阴影颜色aLabel.shadowColor=[UIColor blueColor];//阴影偏移量aLabel.shadowOffset=CGSizeMake(0.5, 0.5);
//是否能和用户交互
aLabel.userInteractionEnabled=YES;
//文字是否可变,默认值是YES
aLabel.enabled=YES;
//设置文字过长时的显示格式
aLabel.lineBreakMode = UILineBreakModeMiddleTruncation; //截去中间
aLabel.lineBreakMode =UILineBreakModeTailTruncation,//截去尾部
aLabel.lineBreakMode =UILineBreakModeHeadTruncation;//截去头部
aLabel.lineBreakMode=UILineBreakModeCharacterWrap;//保留整个字符
aLabel.lineBreakMode=UILineBreakModeClip;//截去多余部分
在定义里面允许有以下格式显示:
// NSParagraphStyletypedef NS_ENUM(NSInteger, NSLineBreakMode) { NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default NSLineBreakByCharWrapping, // Wrap at character boundaries NSLineBreakByClipping, // Simply clip NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz" NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..." NSLineBreakByTruncatingMiddle // Truncate middle of line: "ab...yz"} NS_ENUM_AVAILABLE(10_0,6_0);
相关文章推荐
- unable to load native-hadoop library for your platform using builtin-java classes
- 《Hadoop:The Definitive Guide 4th Edition》Chapter 1 Meet Hadoop
- EasyUI系列学习(六)-Tooltip(提示框)
- Java [Leetcode 303]Range Sum Query - Immutable
- Queue and stack
- UILabel添加删除线,类似团购效果
- SPOJ DQUERY树状数组离线or主席树
- JDBC连接池、监控组件 Druid
- SPOJ DQUERY树状数组离线or主席树
- EasyUI系列学习(五)-Resizable(调整大小)
- Swagger UI 使用
- 分层模型的典型应用和FishiGUI的分层模型
- 4.跟我学solr---SolrRequestHandler具体解释
- 不错的判断 UITextView 内容不超过20个字符串的方法
- JS模块化工具requirejs
- Building Android notifications 2.3 through to 6.0
- Handler官方范例AsyncQueryHandler源码解析
- EasyUI系列学习(四)-Droppable(放置)
- org.hibernate.QueryException: query must begin with SELECT or FROM: delete
- ASTQueryTranslatorFactory weblogic10.3 org.hibernate.hql.ast.HqlToken报错问题