AttributedString - decorated text.

NSMutableAttributedString : NSAttributedString and its mutable counterpart NSMutableAttributedString are used to draw decorated text. 

You can create strings with attributes that describe how the string should look when drawn. 


Show OutLine String on button : If you want to show outline text on button then you can use NSMutableAttributedString.


NSMutableAttributedString *title =[[NSMutableAttributedString alloc] initWithString:@"Rajneesh071"];

[title setAttributes:@{ NSStrokeWidthAttributeName : @3,
                        NSStrokeColorAttributeName : [UIColor blueColor] }
               range:NSMakeRange(0, [title length])];

[yourButton setAttributedTitle:title forState:UIControlStateNormal];

OutPut :


Play with text font : If you want to change font name and font size then you can do like this.

    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:self.outlineButton.currentTitle];
    [string addAttribute:NSFontAttributeName                  value:[UIFont systemFontOfSize:20.0]
                  range:NSMakeRange(0, 3)];
    [self.outlineButton setAttributedTitle:string forState:UIControlStateNormal];
This will change font size of first three char.
OutPut :




(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableAttributedString_Class/Reference/Reference.html)




Comments

Popular posts from this blog

Hacker Rank problem solution

How to Make REST api call in Objective-C.

Building and Running Python Scripts with Xcode