shankywave1
shankywave1

Reputation: 45

How can we use defaultTextAttribute of UITextField?

Can anyone please explain me with example how can I use UITextField defaultTextAttribute property? I searched a lot but didn't find an example on it. I think it is added in ios 7.0 thats why!!

Thanks in advance

Upvotes: 0

Views: 2352

Answers (2)

Rashad
Rashad

Reputation: 11197

If use defaultTextAttributes property you will get only a Dictionary. If you want to set then you have to do some thing like this:

NSString *s = @"Why?";
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:s];
NSInteger _stringLength=[s length];
UIColor *_red=[UIColor redColor];
[attString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:25] range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(0, _stringLength)];
self.textField.attributedText = attString;

Hoe this helps.. :)

Upvotes: 1

Retro
Retro

Reputation: 4005

By default, this property returns a dictionary of text attributes with default values.

Setting this property applies the specified attributes to the entire text of the text field. Unset attributes maintain their default values.

Getting this property returns the previously set attributes, which may have been modified by setting properties such as font and textColor.

NSDictionary* textFieldAttrib = [textField defaultTextAttributes];

this will tell you the preset properties

Upvotes: 0

Related Questions