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

标签 ios swift cocoa-touch

我遇到一个问题,即 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/

相关文章:

swift - 自定义 SDCAlertView

ios - 在 api 调用之前从核心数据表中删除数据在 swift 中不起作用

ios - AFNetworking iOS 添加 curl

ios - 线程 6 : EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP) error using UICollectionWiew

iphone - TBXML 将复杂的 xml 解析为数组

iphone - 尝试将照片库中的图像保存到 iPad 应用程序包中

objective-c - 在给定索引上启动 UIPageViewController

ios - 如何通过FBGraph或FBConnect获取好友墙信息?

ios - 如何在 UITableView 中制作最后的页脚?

objective-c - 将数组从一个 View 添加到另一个 View 并保留值