1、UILabel
 
**//设置文字

label.text = @"欢迎收看灌篮高手,我是安溪教练";
**//设置文字颜色
label.textColor = [UIColor grayColor];
**//默认17号字体
label.font = [UIFont systemFontOfSize:34];
**//对齐方式
label.textAlignment = NSTextAlignmentCenter;
**//设置阴影
label.shadowColor = [UIColor redColor];
//设置阴影映射大小(坐标),默认CGSizeMake(0, -1)
label.shadowOffset = CGSizeMake(-2, -2);
***//断句,展示缩略
label.lineBreakMode = NSLineBreakByTruncatingTail;
**//行数0为自动匹配行数
label.numberOfLines = 1;
***//字体是否适应宽度(Size无效)(将宽度充满)
label.adjustsFontSizeToFitWidth = YES;

//最小字体比例(缩放)

label.minimumScaleFactor = 0.9;

**//label背景色

label.backgroundColor = [UIColor yellowColor];

//设置高亮颜色

label.highlightedTextColor = [UIColor greenColor];

//开启高亮状态

label.highlighted = YES;

//是否隐藏高亮状态

label.hidden = NO;

2、UIFont

//打印苹果自带字体

for (NSString* str in [UIFont familyNames]) {

NSLog(@"%@",str);

NSArray* arr = [UIFont fontNamesForFamilyName:str];

for (NSString* str1 in arr) {

NSLog(@"%@",str1);

}

}

//斜体

[UIFont italicSystemFontOfSize:50];
//字体加粗
[UIFont boldSystemFontOfSize:50];
//设置系统字体

[UIFont systemFontOfSize:10];

//设置自定义字体

[UIFont fontWithName:@"Heiti TC" size:25];

//修改字体

[[UIFont systemFontOfSize:10] fontWithSize:50];

富文本

3、NSAttributedString

NSAttributedString * attribute = [[NSAttributedString alloc] initWithString:string attributes:dictA];

label.attributedText = attribute;

  • addAttributes//分段操作字符串

(字典类型)

NSFontAttributeName:[UIFont systemFontOfSize:20],//字体大小

NSForegroundColorAttributeName:[UIColor greenColor]//字体颜色

NSBackgroundColorAttributeName:[UIColor grayColor]//字体背景颜色

NSParagraphStyleAttributeName:paragraph//段落属性

NSObliquenessAttributeName:@0.5 //斜体

NSStrokeColorAttributeName:[UIColor whiteColor],//边线颜色

NSStrokeWidthAttributeName:@2,//描边

NSKernAttributeName:@20,//字间距

NSStrikethroughStyleAttributeName:@2,//删除线

NSUnderlineStyleAttributeName:@1,  //下划线

段落  
4、NSMutableParagraphStyle 属性

//行间距

paragraph.lineSpacing = 10;

//段间距

paragraph.paragraphSpacing = 50;

//头尾间距(第一行)

paragraph.firstLineHeadIndent = 50;

计算label高度

CGSize size1 =[string boundingRectWithSize:CGSizeMake(self.view.frame.size.width-40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

竖直文本Size计算

CGSize size =  [string boundingRectWithSize:CGSizeMake(字体大小, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

自适应

+ sizeToFit

+ sizeThatFits:(CGSize)

UILabel的简单用法和实际操作的更多相关文章

  1. UIImage的简单用法和实际操作

    png,pdf不需要添加后缀名 jpg添加后缀名 存储 UIImagejpg contentMode属性 这个属性是用来设置图片的显示方式,如居中.居右,是否缩放等,有以下几个常量可供设定: UIVi ...

  2. Linq to SQL 简单的增删改操作

    Linq to SQL 简单的增删改操作. 新建数据库表tbGuestBook.结构如下: 新建web项目,完成相应的dbml文件.留言页面布局如下 <body> <form id= ...

  3. 简单的redis缓存操作(get、put)

    简单的redis缓存操作(get.put) 本文介绍简单的redis缓存操作,包括引入jedisjar包.配置redis.RedisDao需要的一些工具.向redis中放数据(put).从redis中 ...

  4. 【JavaScript】使用setInterval()函数作简单的轮询操作

    轮询(Polling)是一种CPU决策怎样提供周边设备服务的方式,又称"程控输出入"(Programmed I/O). 轮询法的概念是.由CPU定时发出询问.依序询问每个周边设备是 ...

  5. 2.NetDh框架之简单高效的日志操作类(附源码和示例代码)

    前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...

  6. 使用KEIL C51实现的简单合作式多任务操作系统内核(单片机实现版本)

    基于网上网友的代码,自己在单片机上实现, 特此记录分享之. 基于https://blog.csdn.net/yyx112358/article/details/78877523 //使用KEIL C5 ...

  7. 国产化之路-统信UOS + Nginx + Asp.Net MVC + EF Core 3.1 + 达梦DM8实现简单增删改查操作

    专题目录 国产化之路-统信UOS操作系统安装 国产化之路-国产操作系统安装.net core 3.1 sdk 国产化之路-安装WEB服务器 国产化之路-安装达梦DM8数据库 国产化之路-统信UOS + ...

  8. C++ //深拷贝与浅拷贝 //浅拷贝 : 简单的赋值拷贝操作 //深拷贝: 在堆区重新申请空间 进行拷贝操作

    1 //深拷贝与浅拷贝 2 3 //浅拷贝 : 简单的赋值拷贝操作 4 //深拷贝: 在堆区重新申请空间 进行拷贝操作 5 6 7 #include <iostream> 8 using ...

  9. 用php实现一个简单的链式操作

    最近在读<php核心技术与最佳实践>这本书,书中第一章提到用__call()方法可以实现一个简单的字符串链式操作,比如,下面这个过滤字符串然后再求长度的操作,一般要这么写: strlen( ...

随机推荐

  1. JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer

    Description Resource Path Location Type JavaServer Faces 2.2 can not be installed : One or more cons ...

  2. poj1061 青蛙的约会 扩展欧几里德的应用

    这个题解得改一下,开始接触数论,这道题目一开始是看了别人的思路做的,后来我又继续以这种方法去做题,发现很困难,学长告诉我先看书,把各种词的定义看懂了,再好好学习,我做了几道朴素的欧几里德,尽管是小学生 ...

  3. 建表的sql

    1. 创建用户表 create table user( id int unsigned not null primary key auto_increment comment '自增id', user ...

  4. 访问ControlTemplate内部的元素

    需要用到code behind 注意要给需要访问的元素命名x:Name="PART_TextBlock" <ResourceDictionary xmlns="ht ...

  5. url中的scheme

    iPhone上URL Schemes的作用为应用程序提供了一个其他应用程序或者safari可以启动他的方法. --http://blog.sina.com.cn/s/blog_5673c12f0100 ...

  6. Hanganalyze 使用

    It is  important to find the that the reason hangs the database. How can we do, is a headache thing. ...

  7. 数据对象ajax学习篇9

    题记:写这篇博客要主是加深自己对数据对象的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 对ajax工作道理: 下面这段是来自一个网友的blog: Ajax的道理简单来说通过Xml ...

  8. PS-添加前景色

    alt+Delete是填充前景色,即ps左边两个颜色块,前面的那个 ctrl+delete填充背景色

  9. scu 4436: Easy Math 水题

    4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...

  10. Codeforces Round #188 (Div. 2) A. Even Odds 水题

    A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...