//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. 3. UILable 的使用

    1.  坐标系 来自:http://www.cnblogs.com/mcj-coding/p/5100455.html  QQ: 863740091 如果在平面坐标系中我们要确定一个东西的位置和大小需 ...

  2. UI第一节—— UILable

    1.首先说说怎么创建UI程序,打开xcode,选择Create  a new Xcode project.看如下截图 2,接下来就蹦出一个和写OC应用差不多的界面,不多解释了 3.我给工程取得名字就叫 ...

  3. 完美解决 向UILable 文字最后插入N张图片,支持向限制行数的UILable 最后一行插入,多余文字显示...

    效果: ====直接上代码吧=== // // UILabel+StringFrame.h // QYER // // Created by qyer on 15/3/19. // Copyright ...

  4. UIlable 属性详用

    我的好朋友给我制定了一个新的学习方法,从新的看每个控件,去了解他的每个属性,方法来让自己对oc的认识更加充实 今天重新认识一下UILable 的属性lable的阴影设置: 阴影的偏移量是以lable中 ...

  5. iOS UILable高度自适应

    适用于iOS6以后 NSString *tip = @"UILable高度自适应,UILable高度自适应,UILable高度自适应"; UILabel label_2 = [[U ...

  6. IOS学习--UILable使用手册(20150120)

    第一步:创建一个UILable对象 UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; 第二步:设置对象的各种属性 ...

  7. UILable:显示多种颜色的方法

    借用别人封装好的类库,用来显示同一个UILable上的多种颜色的字. 类库可以直接在次博客中下载,下载后别忘留言哦. 类库使用:主要用了CoreText里面的东西,所以在使用类库之前需要引用CoreT ...

  8. UILable  /  UITextField  /   UIButton

    // 获取屏幕大小的view UIView *contentView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; // ...

  9. 如何在UILable上添加点击事件?

    最近开始学习iOS开发,今天上来写第一个iOS笔记 昨天碰到一个需求,在UILable上添加点击事件,网上找了写资料,有人建议用透明的UIButton覆盖,有人建议写一个集成自UILable的类,扩展 ...

随机推荐

  1. system占用80端口的问题

    80端口被占用的问题 首先可以看看是不是iis占用了.如果是的话.修改为其他端口即可. 如果不是.. 在cmd中输入命令netstat -ano 查看是不是system占用了80端口? 如果是syst ...

  2. jquery div 下拉框焦点事件

    这章与上一张<jquery input 下拉框(模拟select控件)焦点事件>类似 这章讲述div的焦点事件如何使用 div的焦点事件与input的焦点事件区别在于 需要多添加一个属性: ...

  3. Swift—继承

    一个类可以继承另一个类的方法,属性和其他特性.当一个类继承其他类时,继承类叫子类,被继承类叫超类(或父类).在Swift中,继承具有单继承的特点,每个子类只有一个直接父类,继承是区分类与其他类型的一个 ...

  4. JSP代码加固

    String id = request.getParameter("id"); String id = id.replace("'","") ...

  5. codeforces B.Fixed Points

    link:http://codeforces.com/contest/347/problem/B 很简单,最多只能交换一次,也就是说,最多会增加两个.可能会增加一个.也可能一个也不增加(此时都是fix ...

  6. h5和h4区别图片

  7. P1382 光棍组织

    我现在TMD连dfs都不会写了 原题: MM 虽然一辈子只要一个,但是也得早点解决.于是,n 个光棍们自发组成了一个光棍组织(ruffian organization,By Wind 乱译).现在,光 ...

  8. Linux软raid创建

    RAID: HBA:基于主机的适配器 RAID:Redundent Array of Inexpensive Disks 廉价磁盘阵列 Independent       独立磁盘阵列 Level:仅 ...

  9. 子句jion

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. 单因素特征选择--Univariate Feature Selection

    An example showing univariate feature selection. Noisy (non informative) features are added to the i ...