Reputation: 45
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
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
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