Tag: 自定义标签

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