一label基本设置

self.view.backgroundColor = [UIColor redColor];

//创建第一个标签控件

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 200, 30)];

//对位置设置

//对控件的中心点进行设置

label.center = self.view.center;

label.frame = CGRectMake(20, 20, 30, 30);

加粗;

[UILabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];

加粗并且倾斜

[UILabel setFont:[UIFont fontWithName:@"Helvetica-BoldOblique" size:20]];

//显示文字

label.text = @"我是美女";

//设置字体大小

label.font = [UIFont systemFontOfSize:30];

//自适应大小的方法   标签的大小由字体的大小长度决定

[label sizeToFit];

//字体的颜色  alpha 透明度 0 - 1   0- 1

label.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:195/255.0 alpha:1];

//Red Green Blue 0 - 255   255  255  255

//  0 - 1

//字体对齐格式  右侧是枚举类型

label.textAlignment = NSTextAlignmentCenter;

//加背景颜色

label.backgroundColor = [UIColor greenColor];

//显示出来 将标签 放到视图上 进行显示

[self.view addSubview:label];

//addSubview 添加子视图

//不是程序崩溃前提下 问题:

//第一点  frame是否设置了

//第二点  是不是加到了父视图中

//第三点  背景色和 控件颜色 一样

二.文字自适应

//创建label

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, 200, 999)];

label.backgroundColor = [UIColor greenColor];

label.text = @"To be or not to be, that is a question。To be or not to be, that is a question。To be or not to be, that is a question。To be or not to be, that is a question。To be or not to be, that is a question。";

label.font = [UIFont systemFontOfSize:18];

label.textColor = [UIColor redColor];

//设置 label的换行模式

label.lineBreakMode = NSLineBreakByWordWrapping; //根据单词进行换行

//设置label显示几行  可以有无限行

label.numberOfLines = 0;

[label sizeToFit];

[self.view addSubview:label];

text  property

font  property

textColor  property

textAlignment  property

lineBreakMode  property

enabled  property

Sizing the Label’s Text

adjustsFontSizeToFitWidth  property

baselineAdjustment  property

minimumFontSize  property   无例

numberOfLines  property

Managing Highlight Values

highlightedTextColor  property

highlighted  property

Drawing a Shadow

shadowColor  property

shadowOffset  property

Drawing and Positioning Overrides

– textRectForBounds:limitedToNumberOfLines: 无例

– drawTextInRect:  无例

Setting and Getting Attributes

userInteractionEnabled  property

UILabel垂直居上对齐[label sizeToFit];

//设置文字过长时的显示格式

label.lineBreakMode = UILineBreakModeWordWrap;

typedefenum {

UILineBreakModeWordWrap =0,           // Wrap at word boundaries

UILineBreakModeCharacterWrap,          // Wrap at character boundaries

UILineBreakModeClip,           //截去多余部分 Simply clip when it hits the end of the rect截去多余部分

UILineBreakModeHeadTruncation, //截去头部Truncate at head of line: "...wxyz". Will truncate multiline text on first line

UILineBreakModeTailTruncation,//截去尾部 Truncate at tail of line: "abcd...". Will truncate multiline text on last line

UILineBreakModeMiddleTruncation,//截去中间 Truncate middle of line:  "ab...yz". Will truncate multiline text in the middle

} UILineBreakMode;

//设置label的行数,这个可以根据上节的UITextView自适应高度

label.numberOfLines = 2;

label.lineBreakMode = UILineBreakModeWordWrap;

label.textAlignment =  UITextAlignmentCenter;//设置文字对齐位置,居左,居中,居右

label.text = @ "123" ;//设置显示文字 

//设置文字颜色,可以有多种颜色可以选择

label.textColor = [UIColor whiteColor];

label.backgroundColor = [UIColor blackColor];

//设置字体:粗体,正常的是 SystemFontOfSize,调用系统的字体配置 

label.font = [UIFont boldSystemFontOfSize:20];

label.font = [UIFont fontWithName:@ "Arial Rounded MT Bold"  size:(36.0)];

//[UIFont fontWithName:@ "Arial" size:14.0]]; //非加粗

//设置文本是否高亮和高亮时的颜色

scoreLabel.highlighted = YES; 

scoreLabel.highlightedTextColor = [UIColor orangeColor]; 

//设置阴影的颜色和阴影的偏移位置 

scoreLabel.shadowColor = [UIColor redColor]; 

scoreLabel.shadowOffset = CGSizeMake(1.0,1.0); 

//设置是否能与用户进行交互 

scoreLabel.userInteractionEnabled = YES;  

//设置label中的文字是否可变,默认值是YES  

scoreLabel.enabled = NO;

//设置字体大小是否适应label宽度 

label.adjustsFontSizeToFitWidth = YES; 

//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为

coreLabel.baselineAdjustment = UIBaselineAdjustmentNone

typedefenum {

UIBaselineAdjustmentAlignBaselines =0,// default. used when shrinking text to position based on the original baseline

UIBaselineAdjustmentAlignCenters,

UIBaselineAdjustmentNone,

} UIBaselineAdjustment;

//最小文字号数

minimumFontSize

设置背景色为透明

scoreLabel.backgroudColor=[UIColor clearColor];

自定义的颜色:

scoreLabel.backgroudColor=[UIColor clearColor];

UIColor *color = [UIColor colorWithRed:1.0f green:50.0f blue:0.0f alpha:1.0f];

scoreLabel.textColor = [UIColor color]

//UIColor 里的 RGB 值是CGFloat类型的在0~1范围内,对应0~255的颜色值范围。

 

- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;

//改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.

- (void)drawTextInRect:(CGRect)rect;

eg:

UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(0, 0, 75, 40)];   //声明UIlbel并指定其位置和长宽label.backgroundColor = [UIColorclearColor];   //设置label的背景色,这里设置为透明色。label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];   //设置label的字体和字体大小。
//lable的旋转label.transform = CGAffineTransformMakeRotation(0.1);     //设置label的旋转角度label.text = @“helloworld”;   //设置label所显示的文本label.textColor = [UIColorwhiteColor];    //设置文本的颜色label.shadowColor = [UIColorcolorWithWhite:0.1falpha:0.8f];    //设置文本的阴影色彩和透明度。label.shadowOffset = CGSizeMake(2.0f, 2.0f);     //设置阴影的倾斜角度。label.textAlignment = UITextAlignmentCenter;     //设置文本在label中显示的位置,这里为居中。
//换行技巧:如下换行可实现多行显示,但要求label有足够的宽度。label.lineBreakMode = UILineBreakModeWordWrap;     //指定换行模式label.numberOfLines = 2;    // 指定label的行数

 

 

 

 

让label自适应里面的文字,自动调整宽度和高度的

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];这个frame是初设的,没关系,后面还会重新设置其size。
[label setNumberOfLines:0];
NSString *s = @"string......";
UIFont *font = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(320,2000);
CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
[label setFrame:CGRectMake:(0,0, labelsize.width, labelsize.height)];
[self.view addSubView:label];
这样就可以对s赋值让其自动调整其大小了。

label 详细用法相关推荐

  1. Vue中v-bind,v-on,v-model都是干什么的(区别以及详细用法)?自制动图,一看就懂 ∠( °ω°)/ 前端知识

    文章目录 区别 详细用法 属性绑定(`v-bind:`或`:`) 单值绑定 多值绑定 绑定style 事件绑定(`v-on`或`@`) 传入event 双向绑定(`v-model`) 双向绑定原理 元 ...

  2. Element Ui使用技巧——Form表单的校验规则rules详细说明;element的 form 表单rules详细用法

    本文章是在项目开发时遇到问题看到的一片好文, 摘录自[博客园]–[逍遥云天]. 感谢作者 地址 – https://www.cnblogs.com/xyyt/p/13366812.html 在 [逍遥 ...

  3. Android命令行工具logcat详细用法!

    logcat是Android中一个命令行工具,可以用于得到程序的log信息. 见板凳详细说明!      本贴内容来自网络,引用网址为:http://hi.baidu.com/%C9%C1%D2%AB ...

  4. __declspec关键字详细用法

    __declspec关键字详细用法 2009-01-21 16:23 __declspec用于指定所给定类型的实例的与Microsoft相关的存储方式.其它的有关存储方式的修饰符如static与ext ...

  5. mysql left/right join算法效率分析_mysql left join,right join,inner join超详细用法分析

    MySQL left join,right join,inner join超详细用法分析 下面是例子分析 表A记录如下: aID        aNum 1           a20050111 2 ...

  6. python sort怎么用,Linux Sort命令详细用法(有实例)

    Linux Sort命令详细用法(有实例) sort是在Linux里非常常用的一个命令,管排序的,集中精力,五分钟搞定sort,现在开始! Linux sort命令进阶: 1 sort的工作原理 so ...

  7. vue性能优化-------vendor优化详细用法(瘦身),减小体积,引入cdn

    vue性能优化-------vendor优化详细用法(瘦身),减小体积,引入cdn 原创ChrisWang_ 最后发布于2019-05-24 10:25:58 阅读数 1332  收藏 展开 vue性 ...

  8. oracle rtrim(),Oracle ltrim() rtrim() 函数详细用法

    嘿嘿,今天在论坛里看了一篇帖子,讨论ltrim() 函数的详细用法,下面我借几个高手的回答总结一下: 先看几个实例: SQL> select ltrim('109224323','109') f ...

  9. pythonrange函数用法_python range()函数详细用法

    python range()函数详细用法 函数原型:range(start, end, scan): 参数含义:start:计数从start开始.默认是从0开始.例如range(5)等价于range( ...

  10. python中3 and not 5_python中not、and和or的优先级与详细用法介绍

    前言 (小白专用)本次所分享的是Python中的not.and.or的执行时的优先级,以及他们的具体用法.本文比较详细,不喜勿喷. 一.not.and.or的含义以及优先级 对象 返回结果 优先顺序 ...

最新文章

  1. 如何用c语言ics文件,大一下学ics,书里在linux上用C编程,刚安系统老师就留了几个作业...
  2. fatal error C1900: Il mismatch between 'P1' version '20060201' and 'P2' version '20050411'
  3. 神经网络模式识别matlab,基于matlab仿真的神经网络模式识别
  4. SAP ME1M如何以ALV形式显示(鹦鹉学舌篇)
  5. python 代码片段6
  6. 页面 接收跳转数据_【实战案例】在线教育渠道落地页数据分析
  7. 详解AST抽象语法树
  8. Docker安装禅道项目管理平台zendao-v11.6.x
  9. sublime html乱码,HTML5 sublime 编码出现乱码怎么处理
  10. 关于标题的多HTML定制
  11. s3c2440的GPIO驱动
  12. Gitlab分支保护
  13. HCIA-IoT V2.5物联网初级考试总结(附题库,历年真题,刷题软件)
  14. 计算机保研夏令营预推免
  15. arduino连接ps2手柄控制智能小车实践记录-续
  16. Raul的新机器学习书!
  17. c++打印素数表(线性筛)
  18. 怎么隐藏CAD文件里的图层?
  19. 迎合国家新政策,共享购联合共享经济,三方互利,消费增值
  20. python解压rar

热门文章

  1. 2013 01 12 三星发布最新八核处理器SoC “Exynos 5 Octa”
  2. 关于AP3211KTR-G1
  3. ADAUDSP1452 声场 Balance与Fader功能的实现
  4. CNN可视化-Guided Grad-CAM
  5. 自己做的js甘特图插件
  6. 面试的反杀-你有没有想要问我的
  7. java 导出word文档
  8. 如何安装Eclipse WTP插件
  9. activiti之奇淫技巧一(自动完成首个任务)
  10. JAVA:实现Lucas Series卢卡斯系列算法(附完整源码)