在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
@IBOutlet weak var content: UILabel! func setup(content:String){ self.content.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 36 let content = "<html><head><meta name= \"viewport\" content= \"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\"></head><body>" + content + "</body></html>" let data:NSData? = content.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true) do { let attrStr = try NSMutableAttributedString(data: data!, options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType], documentAttributes: nil) attrStr.enumerateAttribute(NSAttachmentAttributeName, inRange: NSMakeRange(0, attrStr.length), options: NSAttributedStringEnumerationOptions.Reverse, usingBlock: { (vale, range, stop) -> Void in if let ment = vale as? NSTextAttachment{ ment.bounds.size = CGSizeMake(UIScreen.mainScreen().bounds.size.width - 20, 130) } }) attrStr.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(14), range: NSMakeRange(0, attrStr.length)) // 设置行距 let style = NSMutableParagraphStyle() style.lineSpacing = 5 attrStr.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSMakeRange(0, attrStr.length)) self.content.attributedText = attrStr } catch{ } self.content.font = UIFont.systemFontOfSize(14) self.content.textColor = UIColor.darkGrayColor() }
|
请发表评论