Skip to main content

NSMutableAttributedString

                ****************  Do you want fancy Text    ***************


#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *myLabel;

@end

@implementation ViewController

- (void)viewDidLoad
{
  
    [super viewDidLoad];
  
    // Do any additional setup after loading the view, typically from a nib.
  
    NSString *myString = @"That is a test attributed string.";
  
  
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:myString];
        [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)];
        [str addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleThick) range:NSMakeRange(0, [str length] - 5)];
  
    _myLabel.attributedText = str;
  
  
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


Output: You can see label as below from your simulator, if you would have taken some label and assign above str string to your IBOutlet Label.

Comments

Popular posts from this blog

Disable back swipe gesture in UINavigationController

Disable back swipe gesture in UINavigationController(Back swipe in Navigation is a default feature from iOS 7 onwards)  Below Code will completely remove swipe gesture to all view controllers:(Keep in it your base view controller's ViewDidLoad method) if ([ self . navigationController respondsToSelector : @selector ( interactivePopGestureRecognizer )]) [ self . navigationController . view removeGestureRecognizer : self . navigationController . interactivePopGestureRecognizer ];    Below code will remove to particular viewcontroller: self . navigationController . interactivePopGestureRecognizer . enabled = false ;     ---- --- - --- - - - - - - -- - - -  Have a Happy iOS Objective C + Swift Coding  -- - - - - --- - - -  - - -  - - - - - - -   

UIKit Framework Hierarchy

UIKIT Framework Hierarchy

Middle Level iOS Developer interview questions

Middle Level iOS Developer interview questions 1) App Thinning 2) Steps for pushing application to app store 3) How push notification works 4) How google TEZ app getting near devices for get and send money 5)Retain Concept in iOS 6)Memory management  in iOS 7)ARC means 8) Syntax for shared instance 9) optionals and unwraping 10) Design pattarns 11) Tab bar insertion between screens 12) how to load images in table view using urls for each image by smooth scrolling  13) Extenstions 14)Clousers 15)Life cycles  16)how Table view reusable works?

Like us on Facebbok