How would I go about italicizing a single word in an NSString which will be displayed in a UILabel? Specifically, I don't want all text to be italicized, just one word.
Thanks!
(Edited) I meant UILabel, not UITextField.
I don't think that what you are asking to do is possible (I'd be happy to be proven wrong). However, this library (https://github.com/facebook/three20/) is a popular way to achieve the same result in a UILabel (not text field) . The library works fairly well, but does have a lot of limitations, especially on edge conditions, and of course, it comes with associated overhead.
I'd encourage you to think about other ways of achieving the same user outcome. Can Placeholder text help? How about hints next to your text field?
Good luck.
A native UILabel does not support NSAttributedString which is what is normally used to display strings with formatting. You could try an output the text your self using Core Text but I would suggest checking out FontLabel or the three-20 project mentioned by #JJ Rohrer
Use NSAttributedString... Find controllers to draw NSAttributedString,since UILabel wont support NSAttributedString
Controller for NSAttributedString
Related
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.
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.
I have one label which have a Dynamic string data e.g: "I am Mohit" .I want to make only "am" in bold.Is it Possible in iphone? if yes please give me suggestion.Thanks in advance:)
No you can't have text with different styles in standard UILabel. What you'll probably need to use is NSAttributedString and some custom solution to display them. Check this question for some possible options.
Not with UILabel. Suggest 2 labels, or subclass. Many related answers, including this.
No you can't have text with different styles in standard UILabel.
You need to use NSAttributedString and some custom solution to display them. Check this
done something like this using three20's TTStyledTextLabel :) it works perfectly
you can use textView instead of label to fulfill your requirement.
ex:-
[textview setContentToHTMLString:#""];
how to do the formatting in a UILabel ? for exemple , if i want to make this , Connected as Keving G , "connected as" and "kevin g" have différents colors and size . Should i use 2 UIlabel ?
There's another potential solution, but these might be too complicated for your purposes.
You can use a open source solution like OHAttributedLabel (which uses a NSAttributedString) or a CATextLayer which takes a NSAttributedString as well.
I got these answers from this related question (which includes sample code for OHAttributedLabel).
You have to use two labels and set font accordingly.
You can't do that with a UILabel.
One option is to use a UIWebView and stick HTML inside it...
TTStyledLabel can be used from three20 library
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.