Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let textStorage = NSTextStorage(attributedString: attributedString)
- let layoutManager = NSLayoutManager()
- layoutManager.usesFontLeading = true
- textStorage.addLayoutManager(layoutManager)
- let textContainer = NSTextContainer(size: containerSize)
- layoutManager.addTextContainer(textContainer)
- textContainer.lineFragmentPadding = 0.0
- layoutManager.ensureLayoutForTextContainer(textContainer)
- let tappedIndex = layoutManager.characterIndexForPoint(point,
- inTextContainer: textContainer,
- fractionOfDistanceBetweenInsertionPoints: nil)
- let emojiText = "😀"
- let font = UIFont.systemFontOfSize(20.0)
- let containerSize = CGSize(width: 300.0, height: 20000.0)
- let attributedString = NSAttributedString(string: emojiText, attributes: [NSFontAttributeName: font])
- let textStorage = NSTextStorage(attributedString: attributedString)
- let layoutManager = NSLayoutManager()
- layoutManager.usesFontLeading = true
- textStorage.addLayoutManager(layoutManager)
- let textContainer = NSTextContainer(size: containerSize)
- layoutManager.addTextContainer(textContainer)
- textContainer.lineFragmentPadding = 0.0
- layoutManager.ensureLayoutForTextContainer(textContainer)
- let glyphRect = layoutManager.boundingRectForGlyphRange(NSRange(location: 0, length: attributedString.length), inTextContainer: textContainer)
- let boundingRect = attributedString.boundingRectWithSize(containerSize, options:[.UsesLineFragmentOrigin, .UsesFontLeading], context: nil)
- glyphRect = (0.0, 0.0, 23.0, 28.875)
- boundingRect = (0.0, 0.0, 23.0, 23.8671875)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement