Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make some part of string bold in UITextView or UILabel?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.12k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: