swift中标签的使用
|
1
2
3
4
5
6
7
8
9
10
|
import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() //设置标签x坐标:10,y坐标:20,长:300,宽:100 var label=UILabel(frame:CGRectMake(10,20, 300, 100)) label.text="hangge.com" self.view.addSubview(label); }} |
2,背景颜色和文字颜色的设置
|
1
2
|
label.textColor=UIColor.whiteColor() //白色文字label.backgroundColor=UIColor.blackColor() //黑色背景 |
3,对齐方式的设置
|
1
|
label.textAlignment=NSTextAlignment.Right //文字右对齐 |
4,文字阴影的设置
|
1
2
|
label.shadowColor=UIColor.grayColor() //灰色阴影label.shadowOffset=CGSizeMake(-5,5) //阴影的偏移量 |
5,字体的设置
|
1
|
label.font = UIFont(name:"Zapfino", size:20) |
6,文字过长时的省略方式
|
1
2
3
4
|
label.lineBreakMode=NSLineBreakMode.ByTruncatingTail //隐藏尾部并显示省略号label.lineBreakMode=NSLineBreakMode.ByTruncatingMiddle //隐藏中间部分并显示省略号label.lineBreakMode=NSLineBreakMode.ByTruncatingHead //隐藏头部并显示省略号label.lineBreakMode=NSLineBreakMode.ByClipping //截去多余部分也不显示省略号 |
7,文字大小自适应标签宽度
|
1
|
label.adjustsFontSizeToFitWidth=true //当文字超出标签宽度时,自动调整文字大小,使其不被截断 |
8,使标签可以显示多行文字
|
1
|
label.numberOfLines=2 //显示两行文字(默认只显示一行,设为0表示没有行数限制) |
9,设置文本高亮
|
1
2
3
4
|
//设置文本高亮label.highlighted = true//设置文本高亮颜色label.highlightedTextColor = UIColor.greenColor() |
10,富文本设置
|
1
2
3
4
5
6
7
8
9
10
11
12
|
//富文本设置var attributeString = NSMutableAttributedString(string:"welcome to hangge.com")//从文本0开始6个字符字体HelveticaNeue-Bold,16号attributeString.addAttribute(NSFontAttributeName, value: UIFont(name: "HelveticaNeue-Bold", size: 16)!, range: NSMakeRange(0,6))//设置字体颜色attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSMakeRange(0, 3))//设置文字背景颜色attributeString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.greenColor(), range: NSMakeRange(3,3))label.attributedText = attributeString |
swift中标签的使用的更多相关文章
- swift中的结构体和枚举
Swift 里的结构体非常特殊. 类是面向对象编程语言中传统的结构单元.和结构体相比,Swift 的类支持实现继承,(受限的)反射,析构函数和多所有者. 既然类比结构体强大这么多,为什么还要使用结构体 ...
- 在Swift中实现 oc与swift的混编
在Swift中想要引用OC头文件(import),可采用混编的方法,这里以sqlite为例,采用OC-Swift桥的方式实现添加头文件1引入sqlite数据库的库文件 打开工程配置文件,在build ...
- Swift——(四)Swift中"#"的妙用
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/twlkyao/article/details/31350841 在Swift中," ...
- Swift 中枚举
Swift 中枚举高级用法及实践 字数11017 阅读479 评论0 喜欢20 title: "Swift 中枚举高级用法及实践"date: 2015-11-20tags: [AP ...
- Swift 中的Closures(闭包)详解
Swift 中的Closures(闭包)详解 在Swift没有发布之前,所有人使用OC语言编写Cocoa上的程序,而其中经常被人们讨论的其中之一 -- Block 一直备受大家的喜爱.在Swift中, ...
- swift 中关于open ,public ,fileprivate,private ,internal,修饰的说明
关于 swift 中的open ,public ,fileprivate,private, internal的区别 以下按照修饰关键字的访问约束范围 从约束的限定范围大到小的排序进行说明 open,p ...
- 阿里巴巴最新开源项目 - [HandyJSON] 在Swift中优雅地处理JSON
项目名称:HandyJSON 项目地址:https://github.com/alibaba/handyjson 背景 JSON是移动端开发常用的应用层数据交换协议.最常见的场景便是,客户端向服务端发 ...
- Swift中的可选链与内存管理(干货系列)
干货之前:补充一下可选链(optional chain) class A { var p: B? } class B { var p: C? } class C { func cm() -> S ...
- 在Swift中实现单例方法
在写Swift的单例方法之前可以温习一下Objective-C中单例的写法: + (instancetype)sharedSingleton{ static id instance; static d ...
随机推荐
- make[1]: *** [/workopenwrt/trunk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_nnnnn] Error 2 make[1]: Leaving directory `/work/openwrt/trunk' make: *** [world]
主要原因是编译时未连上网,编译时需要下载些插件,连接网后,重启下系统再编译下.
- 10、end关键字和Fibonacci series: 斐波纳契数列
# Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 #复合赋值表达式,a,b同时赋值0和1 while b < 10: print(b ...
- pscs6
http://wenku.baidu.com/link?url=cO03xdo_GQDdFdeYTDD36ZrjeHarUu4IN-fSEoFAnDXmd5W0yKvzkNWY_vOKKIaKbCdB ...
- DRAM Memory Rank知识
DRAM的一些知识点,先记录下来再进行整理 1.何为Memory rank? A memory rank is a set of DRAM chips connected to the same ch ...
- Fruit Feast
Fruit Feast 题目描述 Bessie has broken into Farmer John's house again! She has discovered a pile of lemo ...
- python 一遍式四则运算
#!/usr/bin/python #coding: utf-8 INTEGER = 'INTEGER' PLUS = '+' MINUS = '-' MUL = '*' DIV = '/' LC = ...
- UWSGITOP-----监控uwsgi 性能
启动 uwsgi -x etc/bfdds_cookiemapping_conf.xml --stats /tmp/stats.socket 查看 uwsgitop /tmp/stats.socket ...
- [Android]SDK安装
安装Android环境时,出现的问题 //在国内安装Android环境时,经常会因为Google服务器的原因,出现链接失败的问题. Failed to fetch URL http://dl-ssl. ...
- 计算器之webservice实现
以下是本人原创,如若转载和使用请注明转载地址.本博客信息切勿用于商业,可以个人使用,若喜欢我的博客,请关注我,谢谢!博客地址 一.根据我的上一篇博客 MyEclipse构建Web Service(Xf ...
- axis2开发实例(一)
主要参考<axis2之webservice新手超详细教程http://wenku.baidu.com/view/6eae036d011ca300a6c390a4.html> <axi ...