Working with NSMutableAttributedString


Code snippet to demonstrate how to use NSMutableAttributedString:


    UILabel *lblTitle = [[UILabel alloc] init];
    [lblTitle setFrame:CGRectMake(2, 180, 320, 25)];
    [self.view addSubview:lblTitle];
    
    NSString *strHello = @"Hello, this is a Demo of NSMutableAttributedString";
    NSRange range;
    NSMutableAttributedString *stringAttributed = [[NSMutableAttributedString alloc]initWithString:strHello];
    [stringAttributed addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:14.0] range:NSMakeRange(0, [strHello length])];
    range = [strHello rangeOfString:@"NSMutableAttributedString"];
    [stringAttributed addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13.0] range:range];
    range = [strHello rangeOfString:@"Demo"];
    [stringAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
    [lblTitle setAttributedText:stringAttributed];



    Follow link for help: Apple Documentation


Comments

Popular posts from this blog

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

payUmoney Payment Gateway Integration in iOS App (Objective C)

Check Internet Connectivity Using AFNetworking 2.0