UILabel text Issue in iphone - iphone

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:#""];

Related

Create UILabel with differently styled text in iOS 5.1, without using storyboards

I would like to create a one lined UILabel with a simple formatting that would look like this:
Never mind the underlining - it's the Photoshop thing.
I basically have 2 parts of the text, the left one with one font family, size and color, and another one with another.
Adding 2 labels one after another would make things extremely problematic and complicated. Any ideas how would you combine the thing into one simple UILabel? thanks in advance!
EDIT: I don't use Storyboards or XIB's and I'm building for iOS 5.1 and up
If you want to run iOS 5.0 and up, you can use the wonderful TTTAttributedLabel by mattt.
I've used both of the following in apps that run in iOS 5+.
https://github.com/mattt/TTTAttributedLabel
https://github.com/AliSoftware/OHAttributedLabel
You can use two UILabels aligned with one another using autolayout, or you can use the attributedText property available in iOS6
You can use attributedText property to handle this.
NSMutableAttributedString* string = [NSMutableAttributedString attributedStringWithString:#"OneThing (AnotherThing)"];
//this sets the font for the whole string
[string setAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"Helvetice-Neue"]}];
//write another font here for "OneThing"
[string setAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"Helvetice-Neue"]} range:NSMakeRange(0, 7)];
myLabel.attributedText = string;

UILabel with Link with more than one line

i want to use UILabel with link.
for that i am using IFTweetLabel which is finding any link and showing a line under it and it is clickable.
but if a string is big then only first line is getting hyperlink instead of complete URL.
as an issue with https://github.com/clawoo/IFTweetLabel/issues/3.
so is there any other option for it , or other library ?
First you have to import RegexKitLite framework. Go through this link. Surely this will help you. It gives same thing as you want.
http://furbo.org/stuff/FancyLabel_1.0.zip
First thing I would like to suggest is
Use UITextView with editing property as NO and it will automatically detect all the links separately similar like the one you need.
textview.editable = NO;
textview.dataDetectorTypes = UIDataDetectorTypeAll;
If you still want to go with UILabel then
You can achieve this by using NSArrtibutedStrings — but I would recommend to use some wrapper around this C-functions. I like OHAttributedLabel.
The demo included shows exactly, how hyperlinks can be handled.
You should give a try to three20 project.
what is the reason for not using UITextView..there is link detection property for UITextView.Your app is not going to get rejected

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.

how to do the formatting in a UILabel

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

Make portion of NSString italicized or bold, not whole string

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