//UILable的大小自适应实例
UILabel *myLable = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];//设定位置与大小
[myLable setFont:[UIFont fontWithName:@"Helvetica" size:20.0]];//格式
[myLable setNumberOfLines:];//行数,只有设为0才能自适应
[myLable setBackgroundColor:[UIColor clearColor]];//背景色
myLable.shadowColor = [UIColor darkGrayColor];//阴影颜色
myLable.shadowOffset = CGSizeMake(., 1.0);//阴影大小 NSString *text = @"abcdefghijklmnopqrstuvwxyz";
UIFont *font = [UIFont fontWithName:@"Helvetica" size:20.0];
CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(175.0f, 2000.0f) lineBreakMode:UILineBreakModeWordWrap];
CGRect rect = myLable.frame;
rect.size = size;
[myLable setFrame:rect];
[myLable setText:text];
myLable.shadowColor = [UIColor darkGrayColor];//阴影颜色
myLable.shadowOffset = CGSizeMake(2.0, 2.0);//阴影大小
[self.view addSubview:myLable];
[myLable release]; //UILable的基本用法
UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 40.0, 200.0, 30.0)];
UILabel *lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 80.0, 200.0, 50.0)];
UILabel *lbl3 = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 140.0, 200.0, 50.0)];
UILabel *lbl4 = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 200.0, 200.0, 50.0)];
UILabel *lbl5 = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 260.0, 200.0, 50.0)];
UILabel *lbl6 = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 320.0, 200.0, 50.0)];
UILabel *lbl7 = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 380.0, 200.0, 50.0)]; //设置显示文字
lbl1.text = @"lable1";
lbl2.text = @"lable2";
lbl3.text = @"lable3--lable3--lable3--lable3--lable3--lable3--lable3--lable3--lable3--lable3--lable3--11个";
lbl4.text = @"lable4--lable4--lable4--lable4--4个";
lbl5.text = @"lable5--lable5--lable5--lable5--lable5--lable5--6个";
lbl6.text = @"lable6";
lbl7.text = @"lable7"; //设置字体:粗体,正常的是SystemFontOfSize
lbl1.font = [UIFont boldSystemFontOfSize:];
//设置文字颜色
lbl1.textColor = [UIColor orangeColor];
lbl2.textColor = [UIColor purpleColor];
//设置背景颜色
lbl1.backgroundColor = [UIColor clearColor];
lbl2.backgroundColor = [UIColor colorWithRed:0.5f green:/255.0f blue:0.3f alpha:0.5f];
//设置字体位置
lbl1.textAlignment = UITextAlignmentRight;
lbl2.textAlignment = UITextAlignmentCenter;
//设置字体的小适应lable的宽度
lbl4.adjustsFontSizeToFitWidth = YES;
//设置lable 的行数
lbl5.numberOfLines = ; //设置高亮
lbl6.highlighted = YES;
lbl6.highlightedTextColor = [UIColor orangeColor];
//设置阴影
lbl7.shadowColor = [UIColor redColor];
lbl7.shadowOffset = CGSizeMake(1.0, 1.0); //设置是否能与用户进行交互
lbl7.userInteractionEnabled = YES;
//设置lable中文字是否可变,默认为YES;
lbl3.enabled = NO;
//设置lable中文字过长时的显示格式
lbl3.lineBreakMode = UILineBreakModeMiddleTruncation; //截去中间
// typedef enum{
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截取头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// }UILineBreakMode; //如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就用来控制文本基线的行为
lbl4.baselineAdjustment = UIBaselineAdjustmentNone;
[self.view addSubview:lbl1];
[self.view addSubview:lbl2];
[self.view addSubview:lbl3];
[self.view addSubview:lbl4];
[self.view addSubview:lbl5];
[self.view addSubview:lbl6];
[self.view addSubview:lbl7]; [lbl1 release];
[lbl2 release];
[lbl3 release];
[lbl4 release];
[lbl5 release];
[lbl6 release];
[lbl7 release];

UILable 的 属性设置的更多相关文章

  1. iOS UILable和属性字符串的使用

    UILable的常用方法和属性 设置文字颜色(默认为黑色) @property(nonatomic,strong) UIColor     *textColor 设置显示文字 @property(no ...

  2. WinForm------DateEdit属性设置

    1.只能选择年份属性设置                       

  3. Composer Player 属性设置

    /// <summary> /// 设置选中名称 /// </summary> /// <param name="name"></para ...

  4. table中bordercolor属性设置后最新ie浏览器或firefox中不显示边线,借助table的css来实现边线

    table中的bordercolor属性设置后在最新的ie或者firefox中均不显示边线,table的边线又是常用功能.只能使用css来实现了,更通用,更方便一些. css: ​.ctable{ b ...

  5. .net 使用Json(),maxJsonLength属性设置的值问题

    “使用JSON JavaScriptSerializer进行序列化或反序列化时出错.字符串的长度超过了为maxJsonLength属性设置的值” 今天业务找我说线上的国家地区都显示数字(地区ID),而 ...

  6. DEV控件:gridControl常用属性设置(转载)

    特别长,先撸下来再说 1.隐藏最上面的GroupPanel  gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值  sValue=T ...

  7. Appium学习实践(二)Python简单脚本以及元素的属性设置

    1.简单的Python脚本 Appium中的设置与Appium学习实践(一)简易运行Appium中的一致 Launch后,执行脚本 #coding:utf-8 import unittest impo ...

  8. DEV控件:gridControl常用属性设置

    1.隐藏最上面的GroupPanel  gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值  sValue=Table.Rows[g ...

  9. [转]浅谈jQuery EasyUI的属性设置

    原文地址:http://www.easyui.info/archives/1664.html 对jQuery EasyUI有一定了解的话,应该知道基本上每一个组件都有一个"options&q ...

随机推荐

  1. 那些年我读过的Blog(Ⅰ)

    序 近期发现自己已经很久很久没有写过文章,其中包括公开的和非公开的Blog,于是自己去翻了以前很多关注的人的Blog,发现也已经有很大一部分没有更新了,遂有了本文,梳理一下自己那些年关注过并且现在已经 ...

  2. CSS中的绝对定位(absolute)误区

    这几天在慕课上看视频学习,偶然听到几个老师都说:CSS绝对定位在没有其他有除static定位的包含块的情况下是以body进行定位,如果要想相对当前元素的父元素来定位,父元素一定要设置position: ...

  3. jQuery ajax 动态append创建表格出现不兼容ie8

    非常多情况下.通过js(jQuery1.10)动态来创建一些样式,对页面的动态交互来说是非常方便的 可是不同的浏览器针对动态生成的不是非常兼容,在此遇见的不兼容ie8.跟各位分享下 代码: json数 ...

  4. Openstack虚拟机创建流程

    续上一篇Openstack安装配置 一,keystone交互认证阶段 1,发送用户名和密码给keystone认证获取token 2,带着token访问nova-api 3,nova-api使用toke ...

  5. Learning PHP Design Patterns

    Learning PHP Design Patterns CHAPTER 1 Algorithms handle speed of operations, and design patterns ha ...

  6. 看用Tornado如何自定义实现表单验证

    我们知道,平时在登陆某个网站或软件时,网站对于你输入的内容是有要求的,并且会对你输入的错误内容有提示,对于Django这种大而全的web框架,是提供了form表单验证功能,但是对于Tornado而言, ...

  7. pycharm-->github / github-->pycharm

    一.pycharm -->发布到--> github:1.github 账号密码 https://github.com/2.git 下载安装 https://git-scm.com/3.配 ...

  8. Web 编程中路径问题

    web.xml 中 <url-pattern> 路径(即 Servlet 路径) 要么以 "*" 开头, 要么以 "/" 开头. 转发和包含路径(服 ...

  9. Set 接口常用子类及其特点

    Set 集合中元素不可重复,是无序的(存入和取出的顺序是不一样的), Set 接口中的方法和 Collection 接口一致. 常用子类: HashSet : 内部数据结构是哈希表, 是不同步的 Li ...

  10. pandas 报错:【sys:1: DtypeWarning: Columns (15) have mixed types. Specify dtype option on import or set low_memory=False.】

    错误原因 报错提示:“sys:1: DtypeWarning: Columns (15) have mixed types. Specify dtype option on import or set ...