I am setting font to UITextView . It works. I am also making the text entered in the UITextView as bold by selecting the text in UITextView. My problem is if I give
font size I cannot make the text bold.
try it .
self.txtView.text=#“Life is an opportunity , Don’t west your time !”;
NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:self.txtView.text];
NSString *word= #"Life is an opportunity";
NSRange range=[self..txtView.text rangeOfString:word];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
[self.txtView setAttributedText:string];
[self.txtView setFont:[UIFont fontWithName:#"Montserrat-Bold" size:15]];
self.txtView.alpha=1;
Related
I am wanting a UILabel where each character is underlined and has a background, while also having a space between the background of each individual character - so essentially each character is in it's own "box"
I have tried using attributedText on a UILabel but having set the NSBackgroundColorAttributeName and NSKernAttributeName the background fills the entire label, essentially I'd like a gap of clear color between each letter.
Is there a way of doing this with attributed text, or will this need to be resolved with another solution?
I currently have tried the following as an example:
NSMutableAttributedString* string = [[NSMutableAttributedString alloc] initWithString:#"EXAMPLE"];
[string addAttribute:NSBackgroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, string.length)]
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, string.length)]
[string addAttribute:NSKernAttributeName value:#(5) range:NSMakeRange(0, [string length])];
[label setAttributedText:string];
Current result:
Desired Result:
(you can ignore the colors, this is just an example)
http://imgur.com/yVkhHon.jpg
I want my text on lines but with separate background. How can i achieve this using UILabel ?
I tried padding etc but nothing works it just show single red box if i select background color for label.
Any help on how to get same effect like image ?
Use the following code:
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:self.yourLabel.text];
//EDITED
[text addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, text.length/2)];
[text addAttribute:NSBackgroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(text.length/2, text.length/2)];
[self.yourLabel setAttributedText: text];
Use NSAttributesString. Create a UILabel, create an NSAttributesString. Then instead of using setText of label, call setAttributedText using the string object you created earlier.
More help on Apple Documentation
[mutableAttributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:selectedRange];
This question already has answers here:
UILabel with text of two different colors
(20 answers)
Closed 8 years ago.
Say i have UIlabel and i want to change color of text at certain word. For example my label text is
"Shop now and get up 50% off Select shoes Limited time offer"
i which "50%" and "Limited" want change color
predefined some word if accrue in label text then change color. fist find and then change color and font or sub string.
To do this use NSAttributedString:
NSMutableAttributedString *text =
[[NSMutableAttributedString alloc]
initWithAttributedString: label.attributedText];
[text addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange(10, 1)];
[label setAttributedText: text];
For details :https://github.com/joaoffcosta/UILabel-FormattedText
You can use NSMutableAttributedString
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:#"Shop now and get up 50% off Select shoes Limited time offer"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(, )];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(, )];
I want to add mandatory field mark in textfield placeholder text like below image please suggest me i am totally confused how to do it
You can use :
NSMutableAttributedString *attriButedString = [[NSMutableAttributedString alloc]initWithString:#"Mandatory*"];
[attriButedString addAttribute:NSForegroundColorAttributeName
value:[NSColor lightGrayColor]
range:NSMakeRange(0, 9)];
[attriButedString addAttribute:NSForegroundColorAttributeName
value:[NSColor redColor]
range:NSMakeRange(9, 1)];
[[self.textField cell] setPlaceholderAttributedString:attriButedString];
This will look like as:
Note: Instead of hard-coded range you can calculate according to your stringlength.
If you are creating TextField from xib click on text field and go to attribute inspecter and fill your placeholder name in placeholder text feild
Try with this.....
[tfSubject setValue:[UIColor colorWithRed:249.0/255.0 green:204.0/255.0 blue:88.0/255.0 alpha:1.0] forKeyPath:#"_placeholderLabel.textColor"];
I need to show both current time (blue color) and buffer limit (gray color) on the same UIProgressView for my AVPlayer instance. Is it possible?
You need to use NSAttributedStrings to accomplish this.
Attributed Strings
Here is an example...
Make a custom UIView that contains a UILabel and UIProgressView as subviews.
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:#"Hello. That is a test attributed string."];
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(3,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(10,7)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:#"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)];
label.attributedText = str;
And here is an example of a custom UIProgressView implementation