Ios 如何使用UITextField的defaultTextAttribute?

Ios 如何使用UITextField的defaultTextAttribute?,ios,uitextfield,Ios,Uitextfield,有人能举例说明我如何使用UITextField defaultTextAttribute属性吗?我搜索了很多,但没有找到一个例子。我认为它是在ios 7.0中添加的,这就是为什么 提前感谢默认情况下,此属性返回具有默认值的文本属性字典 设置此属性将指定的属性应用于文本字段的整个文本。取消设置属性将保持其默认值 获取此属性将返回以前设置的属性,这些属性可能已通过设置字体和文本颜色等属性进行了修改 NSDictionary* textFieldAttrib = [textField defaultT

有人能举例说明我如何使用UITextField defaultTextAttribute属性吗?我搜索了很多,但没有找到一个例子。我认为它是在ios 7.0中添加的,这就是为什么


提前感谢

默认情况下,此属性返回具有默认值的文本属性字典

设置此属性将指定的属性应用于文本字段的整个文本。取消设置属性将保持其默认值

获取此属性将返回以前设置的属性,这些属性可能已通过设置字体和文本颜色等属性进行了修改

NSDictionary* textFieldAttrib = [textField defaultTextAttributes];

这将告诉您预设属性

如果使用defaultTextAttributes属性,您将只获得一个字典。如果要设置,则必须执行以下操作:

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;

这有助于……)

请参见是否可以设置defaultTextAttribute属性?如果是,那么怎么做?是的,您可以这样做,查看@Rashad answer您可以找到属性列表以及在此处设置属性的内容。