If you want to set some part of the UITextview to BOLD then you can implement the following code :-
NSString *str = @"I belong to Dehradun"; // default string
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:str];
UIFont *font_regular = [UIFont fontWithName:@"Helvetica" size:20.0f]; // give the font type
UIFont *font_bold = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
[attString addAttribute:NSFontAttributeName value:font_regular range:NSMakeRange(0, 11)]; // set range and font type value
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(12, nameString.length - 12)];
[self.txtView setAttributedText:attString]; // set the text to the IBOutlet of UITextview
In this code, I have taken a default string , set the font type (BOLD) , given the range and then set the attributed text to the UITextview.
Similarly, we can do this for UILabel.
0 Comment(s)