任何人都可以举例说明我如何使用 UITextField defaultTextAttribute 属性吗?我搜索了很多但没有找到关于它的例子。我认为它是在 ios 7.0 中添加的,这就是原因!!
提前致谢
最佳答案
如果使用 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;
这有帮助..:)
关于ios - 我们如何使用 UITextField 的 defaultTextAttribute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20991249/