2017-08-29 118 views
0

我想在我的UITextField中设置我的文本的颜色。 textborder是黑色的,但里面的颜色是透明的。我如何给它添加颜色?UITextField文本颜色透明

以下是我有:

let memeTextAttributes:[String:Any] = [ 
     NSStrokeColorAttributeName: UIColor.black, 
     NSForegroundColorAttributeName: UIColor.white, 
     NSFontAttributeName: UIFont(name: "HelveticaNeue-CondensedBlack", size: 40)!, 
     NSStrokeWidthAttributeName: 3.0] 

topText.delegate = self 
topText.defaultTextAttributes = memeTextAttributes 
topText.text = "TOP" 
topText.textAlignment = NSTextAlignment.center 
topText.adjustsFontSizeToFitWidth = true 
topText.center.x = self.view.center.x 
topText.center.y = self.view.frame.origin.y + 150 
topText.minimumFontSize = 10 
topText.textColor = UIColor.white 
+0

1.不要同时设置'defaultTextAttirbutes'和'textColor'。 2.默认情况下,文本字段的背景为白色,因此您背景上的白色填充文本可能会使其显示为透明。 – rmaddy

+0

好吧,我删除了textColor语句,但没有帮助。谢谢,还有其他建议吗? – ryanwaite28

+0

你读过我的第二点了吗? – rmaddy

回答

-1

对不起,我误会了你想要的东西。如果您希望背景透明,文本边框颜色为黑色,文本颜色为白色,则应该1)将文本框的backgroundColor属性设置为.clear,2)设置文本框layer属性的borderColor属性3)将文本字段的layer属性的borderWidth属性设置为1,以及4)将文本字段的textColor属性设置为.white

topText.backgroundColor = .clear 
topText.layer.borderColor = UIColor.black.cgColor 
topText.layer.borderWidth = 1 
topText.textColor = .white 
+0

我希望背景透明,文本边框颜色为黑色,文本颜色为白色。像meme生成器如何做。这是一个项目(Udacity ios开发人员nanodegree)。 – ryanwaite28

+0

我如何在字典中设置? – ryanwaite28

+0

刚编辑我的答案来显示它。 –