Reputation: 4843
I am facing a problem to set text alignment in center through HTML. Below is my code
NSString *welcomeStr=[NSString stringWithFormat:@"<div font face='Helvetica Neue' size='5' color = 'black' align=\"center\" ><b>Hello Worlds</b></font> </div> <div font face='Arial' size = '4' color = 'black' align=\"center\">Hi! welcome to my app. I think you all are fine. Thanks for visit our site </font> </div>"];
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[welcomeStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
mylable.attributedText = attrStr;
My output is :
But my problem is i am not getting proper text size what i gave and font name also. By default its coming like image. My font name is Helvetica Neue but its coming different font.
Please anybody help me.
Upvotes: 1
Views: 915
Reputation: 4843
i got my answer. My answer is:
NSString *welcomeStr=[NSString stringWithFormat:@"<div font face='Helvetica Neue' size='5' color = 'black'> <center><b>Hello Worlds</b></center></font> </div> <font face='Arial' size = '4' color = 'black'><center>Hi! welcome to my app. I think you all are fine. Thanks for visit our site</center>"];
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[welcomeStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
mylable.attributedText = attrStr;
Instead of align=\"center\" i add
<center>mytext</center>
Upvotes: 2
Reputation: 4149
Helvetica Neue is not a web-safe font; i.e. not everyone has it on their computer. You need to use a web safe font or import a font for to web. Google provides a library of free fonts for use on the web: https://www.google.com/fonts
You will need to import the font and then assign it to the div. This will best be done as a stylesheet, not as an inline style. Google provides simple instructions and code snippets on how to use their fonts properly.
Upvotes: 0
Reputation: 78
Maybe you get mixed up with @font-face (css).
You must declare in your div something like
<div style="font-family:'Helvetica Neue'; font-size:'16px';"></div>
Be aware that you must import your font if it's not a common font.
Upvotes: 0