gpt4 book ai didi

ios - 获取 UITextField.placeHolder 属性的前景色?

转载 作者:行者123 更新时间:2023-11-29 00:41:16 25 4
gpt4 key购买 nike

我正在尝试获取 UITextField.placeHolder 对象的前景色。我必须使用 NSAttributeString 的以下成员之一:

attributesAtIndex(_:effectiveRange:)
attributesAtIndex(_:longestEffectiveRange:inRange:)
attribute(_:atIndex:effectiveRange:)
attribute(_:atIndex:longestEffectiveRange:inRange:)

有一百万个关于如何设置 NSAttributeString 属性的示例,

uiTextFieldObject.attributedPlaceholder = 
NSAttributedString(string:"placeholder text", attributes[NSForegroundColorAttributeName: UIColor.redColor()])

但我找不到检索 NSAttributeString 属性值的简单示例。任何帮助将不胜感激。

最佳答案

试试这个 - 放置添加验证

swift

let attributedString = NSAttributedString(string: "Temp String",
attributes: [NSForegroundColorAttributeName: UIColor.redColor()])

attributedString.enumerateAttribute(NSForegroundColorAttributeName,
inRange: NSRange(location: 0, length: attributedString.length), options:NSAttributedStringEnumerationOptions(rawValue: 0)){(attribute, range, other) in

if let color = attribute as? UIColor {
print("color \(color)")
}
}

objective-C

NSAttributedString * attributedString = [[NSAttributedString alloc]
initWithString:@"Temp String"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];

[attributedString enumerateAttribute:NSForegroundColorAttributeName
inRange:NSMakeRange(0, attributedString.length)
options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
if (value) {
UIColor *color = (UIColor *)value;
NSLog(@"Color : %@", color);
}
}];

关于ios - 获取 UITextField.placeHolder 属性的前景色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39441652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com