Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created February 26, 2018 13:52
Show Gist options
  • Save vialyx/3e86d8e4f27418f639489b7568a3124b to your computer and use it in GitHub Desktop.
Save vialyx/3e86d8e4f27418f639489b7568a3124b to your computer and use it in GitHub Desktop.
func setData(title: String, timeInterval: NSTimeInterval, description: String) {
let dateNews = NSDate(timeIntervalSince1970: timeInterval)
let dateFormater : NSDateFormatter = NSDateFormatter()
dateFormater.timeZone = NSTimeZone.localTimeZone()
dateFormater.dateFormat = "HH:mm. dd MMMM"
_dateLabel.text = dateFormater.stringFromDate(dateNews)
_titleNewsLabel.text = title
_titleNewsLabel.adjustsFontSizeToFitWidth = false
let constraint = CGSizeMake(_titleNewsLabel.frame.size.width, CGFloat.max);
_titleNewsLabel.frame = (title as NSString).boundingRectWithSize(constraint,
options: [.UsesLineFragmentOrigin,.UsesFontLeading],
attributes: [NSFontAttributeName: _titleNewsLabel.font],
context: nil)
var attrStr: NSMutableAttributedString;
do {
attrStr = try NSMutableAttributedString(data: description.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSDefaultAttributesDocumentAttribute: [NSFontAttributeName: _descriptionLabel.font]],
documentAttributes: nil)
attrStr.addAttribute(NSFontAttributeName, value: _descriptionLabel.font, range: NSMakeRange(0, attrStr.length))
_descriptionLabel.attributedText = attrStr
_descriptionLabel.adjustsFontSizeToFitWidth = false
_descriptionLabel.frame = attrStr.boundingRectWithSize(constraint,
options: [.UsesLineFragmentOrigin, .UsesFontLeading],
context: nil)
} catch {
print(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment