Created
October 2, 2019 07:56
-
-
Save nRewik/7760ac31f107642c70eb9e659862ac3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
let text = "Saw yet kindness too replying whatever marianne. Old sentiments resolution admiration unaffected its mrs literature. (https://www.google.com/), Situation admitting promotion at or to perceived be. Mr acuteness we as estimable enjoyment up. An held late as felt know." | |
let font = UIFont.preferredFont(forTextStyle: .body) | |
let highlightFont = UIFont.preferredFont(forTextStyle: .headline) | |
let attributedText = NSMutableAttributedString(string: text, attributes: [ | |
.font : font | |
]) | |
attributedText.addAttributes([ | |
.font: highlightFont, | |
.foregroundColor: UIColor.systemBlue, | |
.underlineStyle: NSUnderlineStyle.single.rawValue | |
], range: NSRange(location: 118, length: 23)) | |
let constraintSize = CGSize(width: 250, height: CGFloat.greatestFiniteMagnitude) | |
let height_with_font_leading = attributedText.boundingRect(with: constraintSize, | |
options: [.usesLineFragmentOrigin, .usesFontLeading], | |
context: nil).height | |
let height_with_no_font_leading = attributedText.boundingRect(with: constraintSize, | |
options: [.usesLineFragmentOrigin], | |
context: nil).height | |
// "202.87109375" | |
print(height_with_font_leading) | |
// "218.287109375" | |
print(height_with_no_font_leading) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment