iOS UITextView 下划线样式自定义 - dash=0.1, gap=4, dash cap=round
要将UITextView的下划线样式修改为参数为dash = 0.1, gap = 4, dash cap = round,你可以使用NSAttributedString来设置UITextView的属性。\n\n首先,创建一个NSMutableAttributedString对象,并将其应用于UITextView的属性文本。\n\nswift\nlet attributedString = NSMutableAttributedString(string: \"Your text\")\n\n\n然后,将下划线样式应用于NSMutableAttributedString对象。\n\nswift\nlet attributes: [NSAttributedString.Key: Any] = [\n .underlineStyle: NSUnderlineStyle.patternDash.rawValue,\n .underlineColor: UIColor.black,\n .underlineThickness: 1.0,\n .underlinePatternDash: NSNumber(value: 0.1),\n .underlinePatternGap: NSNumber(value: 4),\n .underlinePatternDashCap: NSUnderlineStyle.LineCapStyle.round.rawValue\n]\n\nattributedString.addAttributes(attributes, range: NSRange(location: 0, length: attributedString.length))\n\n\n最后,将NSMutableAttributedString对象应用于UITextView的属性文本。\n\nswift\ntextView.attributedText = attributedString\n\n\n这样,UITextView的下划线样式就会被修改为参数为dash = 0.1, gap = 4, dash cap = round。
原文地址: https://www.cveoy.top/t/topic/pKfn 著作权归作者所有。请勿转载和采集!