Created
June 28, 2020 11:01
-
-
Save Ajimi/d402d765750036a64405fae04fd3eb96 to your computer and use it in GitHub Desktop.
This file contains 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
// Create Attachment | |
let imageAttachment = NSTextAttachment() | |
imageAttachment.image = UIImage(named:"iPhoneIcon") | |
// Set bound to reposition | |
let imageOffsetY: CGFloat = -5.0 | |
imageAttachment.bounds = CGRect(x: 0, y: imageOffsetY, width: imageAttachment.image!.size.width, height: imageAttachment.image!.size.height) | |
// Create string with attachment | |
let attachmentString = NSAttributedString(attachment: imageAttachment) | |
// Initialize mutable string | |
let completeText = NSMutableAttributedString(string: "") | |
// Add image to mutable string | |
completeText.append(attachmentString) | |
// Add your text to mutable string | |
let textAfterIcon = NSAttributedString(string: "Using attachment.bounds!") | |
completeText.append(textAfterIcon) | |
self.mobileLabel.textAlignment = .center | |
self.mobileLabel.attributedText = completeText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment