Swift 4中的自定义标签效果
在您的应用程序中创建自定义标签效果没什么大不了的,您可以在这里轻松地以自己的方式实现,这里我向您展示了UILabel extension
一些示例。 在不使用任何Custom类的情况下,并且使用非常少且可重复使用的代码,即可轻松自定义任何标签。
为轮廓效果制作自定义标签
让strokeTextAttributes = [
NSAttributedStringKey。 strokeColor :UIColor。 红色 ,
NSAttributedStringKey。 前景色 :UIColor。 白色
NSAttributedStringKey。 strokeWidth : -4.0 ,
NSAttributedStringKey。 字体 :UIFont.boldSystemFont(ofSize: 30 )]
为[NSAttributedStringKey:任何]
//在这里画轮廓
labelOutLine .attributedText = NSMutableAttributedString( 字符串 : “您的轮廓文本” ,属性: strokeTextAttributes )
为UnderLine效果制作自定义标签
let attributedString = NSMutableAttributedString( string : “您的下划线文字” )
attributedString.addAttribute(NSAttributedStringKey.underlineStyle,值:NSUnderlineStyle.styleSingle.rawValue,范围:NSRange(位置:0,长度: attributedString.length ))
//这里有下划线效果
labelUnderLine。 attributedText = attributedString
- 如何设置UITabBarController视图?
- NSPredicate – 无法解析格式字符串
- 在Xcode 8.1中使用XVim的2个快速步骤
- 如何确定在iOS设备上是否安装了Dropbox?
- 将文本字段限制为一个小数点input,仅限数字,小数点后两个字符 – Swift 3
- 将多个audio文件合并为一个
- UIATarget captureScreenWithName()的XCUIApplication替换
- 如何创buildUISearchController,因为UISearchDisplayController在iOS 8中已被弃用?
- 我是否必须在Objective-C for iOS中保留块?