我有很多UITextfield,我想添加一个不同颜色的占位符。我试图添加扩展,而不是每次重复代码,以使它干净。我写过这样的东西,但不能继续了。
我的attributedPlaceholder代码是
emailTextField.attributedPlaceholder = NSAttributedString(string:"EMAIL ADDRESS",
attributes:[NSForegroundColorAttributeName: UIColor.redColor()])我的分机:
import Foundation
import UIKit
extension NSAttributedString {
class func attributedPlaceholderString(string: String, withColor color: UIColor) -> NSAttributedString {
let attributedString = NSAttributedString(string:string, attributes:[NSForegroundColorAttributeName: color])
return attributedString
}
}但当我写
emailTextField.attributedPlaceholder. 我无法获得在扩展中创建的类的名称。请问我的问题在哪里?
发布于 2015-11-05 11:30:50
密码是
emailTextField.attributedPlaceholder = NSAttributedString.attributedPlaceholderString("EMAIL ADDRESS", withColor: UIColor.redColor())您必须考虑到您已经创建了一个类方法(通过使用class命令),所以您必须在类NSAttributedString上调用该方法
https://stackoverflow.com/questions/33543362
复制相似问题