UILabel
2019-04-24 本文已影响0人
79d12e22ec53
UIKit常用控件
UILabel
UILabel 不同样式
UiButtonType: .system
.contactAdd
.detailDisclosure
.infoDark
.infoLight
.roundedRect
UILabel 按钮状态
UIControlState.normal | 正常 |
---|---|
UIControlState.hightlighted | 高亮 |
UIControlState.disabled | 禁用 |
UIControlState.selected | 选中 |
UIControlState.focused | 焦点 |
UIControlState.application | 应用程序使用的附加状态 |
UIControlState.reserved | 保留为内部框架使用 |
UIButton 按钮事件响应
button.addTarget(self, action: , for: .UIController.Events.touchUpInside)
UIlabel 标签控件
//label 常用设置
label.text
label.textColor
label.backgroundColor
label.textAlignment = NSTextAlignment.right
label.shadowColor
label.shadowOffset
label.font=UIFont.systemFont(ofSize: 20)//一般方法
label.font=UIFont.boldSystemFont(ofSize: 20)//加粗方法
label.font=UIFont.init(name:"Avenir-Oblique", size: 20)////指定字体的方法
长文本换行
label.text =
label.numberOfLines = 0
lable.lineBreakMode = NSLineBreakMode.byTruncatingTail //结尾以。。。省略
UILabel 的NSLineBreakMode样式列表
byWordWrapping | 换行发生在单词边界上 |
---|---|
byCharWrapping | 换行发生在到达标签的第一个字符前 |
byClipping | 超过容器边界的文本行内容不会被绘制 |
byTruncatingHead | 在行首剪切,并以。。表示被剪切文字 |
byTruncatingTail | 在行尾剪切,并以。。表示被剪切文字 |
byTruncatingMiddle | 在行中剪切,并以。。表示被剪切文字 |
标签文字样式的自定义
ss富文本的简单实现
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.lightGray
let attributedText = NSMutableAttributedString(string: "hanyueminhaoshuai.com")
attributedText.addAttribute(NSAttributedString.Key.font, value: UIFont.boldSystemFont(ofSize: 48), range: NSMakeRange(0, 4))
attributedText.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.purple, range: NSMakeRange(4, 7))
attributedText.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.orange, range: NSMakeRange(11, 3))
let label = UILabel(frame: CGRect(x: 20, y: 100, width: 280, height: 60))
label.attributedText = attributedText
self.view.addSubview(label)
}
}