gpt4 book ai didi

ios - UITextField NSForegroundColor 在屏幕旋转 Swift 后变为透明

转载 作者:行者123 更新时间:2023-11-28 11:18:25 25 4
gpt4 key购买 nike

我遇到一个问题,即 UITextField 字体前景色在屏幕旋转后变为透明。下面是我的代码。

let TextAttributes = [
NSStrokeColorAttributeName : UIColor.blackColor(),
NSForegroundColorAttributeName : UIColor.whiteColor(),
NSFontAttributeName : UIFont(name: "HelveticaNeue-CondensedBlack", size: 40)!,
NSStrokeWidthAttributeName : 3.0
]

//In viewDidLoad
textFieldTop.delegate = textFieldTopDelegate
textFieldTop.text = "TOP"
textFieldTop.frame = CGRectMake(0, 88, self.view.frame.width, 44)
textFieldTop.defaultTextAttributes = TextAttributes
self.view.addSubview(textFieldTop)
textFieldTop.textAlignment = NSTextAlignment.Center

textFieldBottom.delegate = textFieldBottomDelegate
textFieldBottom.text = "BOTTOM"
textFieldBottom.frame = CGRectMake(0, self.view.frame.height - 88, self.view.frame.width, 44)
textFieldBottom.defaultTextAttributes = TextAttributes
self.view.addSubview(textFieldBottom)
textFieldBottom.textAlignment = NSTextAlignment.Center

//in didRotateFromInterfaceOrientation
textFieldTop.frame = CGRectMake(0, 88, self.view.frame.width, 44)
textFieldTop.defaultTextAttributes = TextAttributes
self.view.addSubview(textFieldTop)
textFieldTop.textAlignment = NSTextAlignment.Center
textFieldBottom.frame = CGRectMake(0, self.view.frame.height - 88, self.view.frame.width, 44)
textFieldBottom.defaultTextAttributes = TextAttributes
self.view.addSubview(textFieldBottom)
textFieldBottom.textAlignment = NSTextAlignment.Center

如何确保前景文本颜色在旋转后不会自动变为透明?

谢谢!

更新

我意识到我的问题不是来自轮换。由于某种原因,前景色是透明的,无法设置。

最佳答案

原来我需要将 NSStrokeWidthAttributeName 设置为 -3

关于ios - UITextField NSForegroundColor 在屏幕旋转 Swift 后变为透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30316230/

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