Integrating HTML tags with text - iphone

Is there a way to directly use HTML tags in iPhone SDK? I was wondering how could I display the following text using HTML in a UILabel :
My name is Nitish and I am 24 years old.

It does not seem to be allowed. Look at following post as well:
iPhone - UILabel containing text with multiple fonts at the same time
Look at this alternative as well:
iPhone - UILabel containing text with multiple fonts at the same time (another asnwer)

You can't use UILabel to display richtext, you will have to move to CoreText.
https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML will allow you to create NASttributeString from HTML source.

This library might help.
https://github.com/elijahdou/RTLabel
Simple rich text display for iOS using html-like markups

Related

Displaying Emojis from Twitter api?

I have an app that retrieves a user's stream and puts it into a UITableView. However, some include emojis (those little smile faces in iOS), and they just return as boxes in my UILabel.
I've done some research, and I still can't figure it out. Does the text type need to be changed?
Thanks!
Please explain your problem better,from the piece that i understood,notice that emojis have native support in iPhone,so any app can display an emoji in a text box,i recommend you to check the methods you're using to add text to the uitableview and the text encoding from the string which is being displayed,also you could check this link
use NSString drawinrect to display emoji instead of drawGlyphsForGlyphRange.

iOS - stringWithFormat change part of the text color

I'm pulling in tweets for my application and I want to be able to format my tweets in a certain way and color. For example, here would be a simple tweet...
"#somename This is a sample tweet from twitter. - 7 hours ago"
Is it possible to take the last part of the string, in this case the "7 hours ago" and change the font / font color?
I'm using stringWithFormat: in order to format in this way:
tweet = [NSString stringWithFormat:#"%#%#", title, time];
But I am unsure if I am able to change the time font and color using this code.
Anyone done this before?
Edit
I've attempted this using AliSoftware's OHAttributedLabel, but I am using ARC and this doesn't seam to be working for me.
Is there a standard "iOS" way of accomplishing this? Maybe using NSAttributedString possibly?
You could use Core Text. Maybe the following question would help you Is it possible to set different font in One UIlabel?
You have to import CoreText.framework in your App
NSStrings don't know about fonts. Have a look at NSAttributedString and Core Text. References:
Text, Web, and Editing Programming Guide for iOS
NSAttributedString Class Reference
UILabel with two different color text
iPhone - UILabel containing text with multiple fonts at the same time
The font/font color are not inherent attributes of the data type NSString. You could use two separate UILabels, or create a small UIWebView to format the text.

Using iOS 5 rich text editor

as you know the Mail app in iOS 5 have a rich text editor is there any possible way to use this feature for a regular UITextView ?
I know of two fundamental approaches to creating a rich text editor in iOS 5:
Use Core Text and a custom view. I don't have any experience with this approach.
Use a UIWebView (instead of a UITextView) and the contentEditable HTML attribute. The basic idea is to load a custom HTML document from your app resources directory. The bare minimum that it needs is this:
<div contentEditable>TEXT_PLACEHOLDER</div>
To initialize the rich text editor view:
1. Load the contents of this file into an NSMutableString and replace the TEXT_PLACEHOLDER string with the text you want to edit.
2. Send the loadHTMLString:baseURL: message to the UIWebView with that HTML string.
Now you have a UIWebView displaying your text inside a div with contentEditable. At this point, you should be able to run your app tap on the text, and be presented with a cursor and be able to add/remove text. The next step is to add rich text formatting functionality. This is done with a set of simple javascript function calls. See the Mozilla documentation on contentEditable for a great reference. You will also want to add a Javascript function to your HTML template file like this:
function getHtmlContent() { return document.getElementById('myDiv').innerHTML; }
So you can easily retrieve the edited text as HTML using [myWebView stringByEvaluatingJavaScriptFromString:#"getHtmlContent()"]. You can also add custom context menu items like you show in the screen shot in your question.
If you have access to the Apple iOS dev center, the WWDC session Rich Text Editing in Safari on iOS talks all about this approach.
A variation of this approach is to use a third-party rich text editor like TinyMCE. I've heard of some success with integrating this into a UIWebView in iOS 5. Again this relies on the contentEditable attribute.
Here is my implementation. Still haven't added UIMenuController functionality, but it's planned to be added soon.
https://github.com/aryaxt/iOS-Rich-Text-Editor
The iOS 5 rich text edit control is also present in the notes app in iOS 4 (make a rich text note on the computer and sync it to see).
This is a custom Apple-made control which they use in their own apps, but it is not published in any official developer API. It's probably in the SDK somewhere, but because it is undocumented, even if you find it and use it, Apple will reject your app.
Basically, if you want a rich text control you will have to make your own.
Edit: Try using this: https://github.com/omnigroup/OmniGroup/tree/master/Frameworks/OmniUI/iPad/Examples/TextEditor/. I haven't used it, so I don't know how well it will work. (Link from this question)
look at https://github.com/gfthr/FastTextView which is more good open source editor than Omni editor

String with different font

I am having a string message i need first word of that as bold font and rest normal.
Making different label can be create problems,(need to find the size of first the make other and then make other,text is in 4 line).
How can i use NSAttributedString here. I could found How do you use NSAttributedString?
but using this shows undeclared NSForegrou... (present in app kit framework).But could not found app kit framework on sdk 4.2
Need help for making such kind of string(bold + normal text).
Go through the below blog tutorial with code, they have different font with NSAttributedString.
http://www.cocoanetics.com/2011/01/rich-text-editing-on-ios/
https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML
https://github.com/omnigroup/OmniGroup/tree/master/Frameworks/OmniUI/iPad/Examples/TextEditor
May I point you to the CoreText Framework and Befriending Core Text on cocoanetics.com. This will show you how to format text.

Multiple UILabel or just one?

I have a text which looks like the following,
the url of the page is http://www.myurl.com, and the phone # is (999)999-9999, blah blah blah...
And I want to show it in a way such that the URL and the phone # are both in different color and bolded. Can I do it using just one UILabel control, or I need to parse them out and put them onto separate UILabel controls. (Note that the text itself could span multiple lines.) How can I do it?
Sorry I forgot to mention that this is for iPhone (CoCoa Touch), where the NSAttributedString is not available.
You might want to check out TTTAttributedLabel. It supports automatic data detection for things like Phone Numbers and URLs, as well as mixed styles with NSAttributedStrings.
You could use an NSAttributeString to decorate your string. There is a good explanation of how to use them here Change the background color of a substring of a drawn NSString?
You could try using a UIWebView, which detects both URLs and phone numbers.