iOS控件之UILabel
2016-06-01 12:29
381 查看
一,LabelDemo
二,Label属性
//创建uilabel
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, 280, 80)];
//设置背景色
label1.backgroundColor = [UIColor grayColor];
//设置tag
label1.tag = 91;
//设置标签文本
label1.text = @CCBASE.NET!;
//设置标签文本字体和字体大小
label1.font = [UIFont fontWithName:@Arial size:30];
//设置文本对齐方式
label1.textAlignment = UITextAlignmentCenter;
//文本对齐方式有以下三种
//typedef enum {
// UITextAlignmentLeft = 0,左对齐
// UITextAlignmentCenter,居中对齐
// UITextAlignmentRight, 右对齐
//} UITextAlignment;
//文本颜色
label1.textColor = [UIColor blueColor];
//超出label边界文字的截取方式
label1.lineBreakMode = UILineBreakModeTailTruncation;
//截取方式有以下6种
//typedef enum {
// UILineBreakModeWordWrap = 0, 以空格为边界,保留整个单词
// UILineBreakModeCharacterWrap, 保留整个字符
// UILineBreakModeClip, 到边界为止
// UILineBreakModeHeadTruncation, 省略开始,以……代替
// UILineBreakModeTailTruncation, 省略结尾,以……代替
// UILineBreakModeMiddleTruncation,省略中间,以……代替,多行时作用于最后一行
//} UILineBreakMode;
//文本文字自适应大小
label1.adjustsFontSizeToFitWidth = YES;
//当adjustsFontSizeToFitWidth=YES时候,如果文本font要缩小时
//baselineAdjustment这个值控制文本的基线位置,只有文本行数为1是有效
label1.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
//有三种方式
//typedef enum {
// UIBaselineAdjustmentAlignBaselines = 0, 默认值文本最上端于label中线对齐
// UIBaselineAdjustmentAlignCenters,//文本中线于label中线对齐
// UIBaselineAdjustmentNone,//文本最低端与label中线对齐
//} UIBaselineAdjustment;
//文本最多行数,为0时没有最大行数限制
label1.numberOfLines = 2;
//最小字体,行数为1时有效,默认为0.0
label1.minimumFontSize = 10.0;
//文本高亮
label1.highlighted = YES;
//文本是否可变
label1.enabled = YES;
//去掉label背景色
//label1.backgroundColor = [UIColor clearColor];
//文本阴影颜色
label1.shadowColor = [UIColor grayColor];
//阴影大小
label1.shadowOffset = CGSizeMake(1.0, 1.0);
//是否能与用户交互
label1.userInteractionEnabled = YES;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor whiteColor]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(90, 100, 140, 40)]; label.backgroundColor = [UIColor redColor]; label.text = @"abcdefgkdkdkdkdkdkdkdkd"; // label.font = [UIFont systemFontOfSize:14]; // label.numberOfLines = 0; // no limit 默认文本是一行显示 label.lineBreakMode = NSLineBreakByTruncatingHead; //label宽度不够时,对文本进行打断的方式 //NSLineBreakByTruncatingHead文本太长会在前面显示... label.shadowColor = [UIColor yellowColor];//阴影颜色 label.shadowOffset = CGSizeMake(-2, 2);//偏移量 label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor blueColor]; [label sizeToFit];//文本内容比较长会自适应 [self.window addSubview:label]; [label release]; [self.window makeKeyAndVisible]; return YES; }
二,Label属性
//创建uilabel
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, 280, 80)];
//设置背景色
label1.backgroundColor = [UIColor grayColor];
//设置tag
label1.tag = 91;
//设置标签文本
label1.text = @CCBASE.NET!;
//设置标签文本字体和字体大小
label1.font = [UIFont fontWithName:@Arial size:30];
//设置文本对齐方式
label1.textAlignment = UITextAlignmentCenter;
//文本对齐方式有以下三种
//typedef enum {
// UITextAlignmentLeft = 0,左对齐
// UITextAlignmentCenter,居中对齐
// UITextAlignmentRight, 右对齐
//} UITextAlignment;
//文本颜色
label1.textColor = [UIColor blueColor];
//超出label边界文字的截取方式
label1.lineBreakMode = UILineBreakModeTailTruncation;
//截取方式有以下6种
//typedef enum {
// UILineBreakModeWordWrap = 0, 以空格为边界,保留整个单词
// UILineBreakModeCharacterWrap, 保留整个字符
// UILineBreakModeClip, 到边界为止
// UILineBreakModeHeadTruncation, 省略开始,以……代替
// UILineBreakModeTailTruncation, 省略结尾,以……代替
// UILineBreakModeMiddleTruncation,省略中间,以……代替,多行时作用于最后一行
//} UILineBreakMode;
//文本文字自适应大小
label1.adjustsFontSizeToFitWidth = YES;
//当adjustsFontSizeToFitWidth=YES时候,如果文本font要缩小时
//baselineAdjustment这个值控制文本的基线位置,只有文本行数为1是有效
label1.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
//有三种方式
//typedef enum {
// UIBaselineAdjustmentAlignBaselines = 0, 默认值文本最上端于label中线对齐
// UIBaselineAdjustmentAlignCenters,//文本中线于label中线对齐
// UIBaselineAdjustmentNone,//文本最低端与label中线对齐
//} UIBaselineAdjustment;
//文本最多行数,为0时没有最大行数限制
label1.numberOfLines = 2;
//最小字体,行数为1时有效,默认为0.0
label1.minimumFontSize = 10.0;
//文本高亮
label1.highlighted = YES;
//文本是否可变
label1.enabled = YES;
//去掉label背景色
//label1.backgroundColor = [UIColor clearColor];
//文本阴影颜色
label1.shadowColor = [UIColor grayColor];
//阴影大小
label1.shadowOffset = CGSizeMake(1.0, 1.0);
//是否能与用户交互
label1.userInteractionEnabled = YES;
相关文章推荐
- LeetCode:Increasing Triplet Subsequence
- 1099. Build A Binary Search Tree (30)
- UIRL编码
- 【kaldi】Kaldi tutorial翻译之Prerequisites(前提条件)-kaldi学习前必备梳理
- java.lang.IllegalArgumentException: No converter found for return value of type: class
- SystemUI浅析
- Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~
- Android 子线程更新UI:handle和runOnUiThread()
- pch文件导入uikit报错 could not build module 'uikit'
- 【iOS开发-91】GCD的同步异步串行并行、NSOperation和NSOperationQueue一级用dispatch_once实现单例(转载)
- Codeforces 645E Intellectual Inquiry (贪心+DP)
- Tair-淘宝自主开发的一个分布式key/value存储系统
- j2ee四大作用域pagecontext,request,session,ServletContext(转)
- 三维箭头quiver3的用法
- UEFI BIOS模式下Windows系统启动过程以及引导文件修复方法
- Android标题透明沉浸式UI
- uestc水题CD Making
- MySQL 导入的问题 Lost connection to MySQL server during query
- QuickWebApi:使用Lambada方式,完成对WebApi的开发和调用。
- SQLiteDatabase中query、insert、update、delete方法参数说明