Last active
October 3, 2023 01:08
-
-
Save startupcode/fa832a15c6cb38b65f6fb4f74462b819 to your computer and use it in GitHub Desktop.
Swift - Assign HTML to NSAttributedString with custom FONT
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
//Usage | |
lbl.attributedText = htmlToAttributedString ("html text") | |
//Assign attributed string | |
func htmlToAttributedString(string : String) -> NSAttributedString{ | |
var attribStr = NSMutableAttributedString() | |
do {//, allowLossyConversion: true | |
attribStr = try NSMutableAttributedString(data: string.dataUsingEncoding(NSUnicodeStringEncoding)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) | |
let textRangeForFont : NSRange = NSMakeRange(0, attribStr.length) | |
attribStr.addAttributes([NSFontAttributeName : UIFont(name: "Arial", size:15)!], range: textRangeForFont) | |
} catch { | |
print(error) | |
} | |
return attribStr | |
} |
Author
startupcode
commented
Dec 19, 2022
via email
Hi
As this is old code and I'm currently not maintaining it. I will check it
and get it fixed though. Thank you for finding the bug in relation to
latest version. Appreciate it.
…On Sun, Dec 18, 2022 at 3:34 PM Nike Kov ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
The both of these gists would break markdown. For example monospace and
italic text style. This could help, but not working with custom fonts
https://stackoverflow.com/a/33828793/5790492
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/fa832a15c6cb38b65f6fb4f74462b819#gistcomment-4406541>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADXGP566WPQJO6CXB4W3UX3WN3ORFBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTONJUGQ3TEMFHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
--
*Regards*
*---------------------------------------------------------------------------------------*
[image: facebook] <https://www.facebook.com/Vlogboard/>
[image: twitter] <https://twitter.com/myvlogboard>
[image: linkedin] <https://www.linkedin.com/in/pm-rakeshkumar>
[image: instagram] <https://www.instagram.com/vlogboard>
Rakesh Kumar
Project Manager
Information Technology | Baltech
Working Hours: 9.30 am to 7.30 pm
9950626730
***@***.***
http://www.vlogboard.com
Jaipur
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment