ios - 为什么我的 BottomText 边框没有禁用,但 topText 可以正常工作?

标签 ios swift uitextfield

class ViewController: UIViewController, UIImagePickerControllerDelegate,
    UINavigationControllerDelegate, UITextFieldDelegate {

@IBOutlet weak var topText: UITextField!
@IBOutlet weak var bottomText: UITextField!
@IBOutlet weak var imagePickerView: UIImageView!

//let stokeColor = NSStrokeColorAttributeName("stoke")

let memeTextAttributes:[String:Any] = [
    NSAttributedStringKey.strokeColor.rawValue: UIColor.blue/* TODO: fill in appropriate UIColor */,
    NSAttributedStringKey.foregroundColor.rawValue: UIColor.cyan/* TODO: fill in appropriate UIColor */,
    NSAttributedStringKey.font.rawValue: UIFont(name: "HelveticaNeue-CondensedBlack", size: 40)!,
    NSAttributedStringKey.strokeWidth.rawValue: 0.5/* TODO: fill in appropriate Float */]

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    topText.textAlignment = .center
    topText.text = "TOP"
    topText.delegate = self
    topText.borderStyle = .none
    topText.defaultTextAttributes = memeTextAttributes

    bottomText.textAlignment = .center
    bottomText.text = "BOTTOM"
    bottomText.delegate = self
    topText.borderStyle = .none
    bottomText.defaultTextAttributes = memeTextAttributes
}

最佳答案

看起来是因为您在 topText 上设置了两次边框样式...

topText.textAlignment = .center
topText.text = "TOP"
topText.delegate = self

// you set top text border style to none here...
topText.borderStyle = .none
topText.defaultTextAttributes = memeTextAttributes

bottomText.textAlignment = .center
bottomText.text = "BOTTOM"
bottomText.delegate = self

// then set it again here... pretty sure you want this to be bottomText.borderStyle = .none
topText.borderStyle = .none
bottomText.defaultTextAttributes = memeTextAttributes

关于ios - 为什么我的 BottomText 边框没有禁用,但 topText 可以正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51904918/

相关文章:

ios - 我想使用 swift 添加标签或文本,如下图所示

iphone - Core Animation (CABasicAnimation) 的不可预测行为

objective-c - 了解使用 != 返回 BOOL 的方法

ios - 我们可以在 Swift 中通过扩展添加静态存储变量吗?

ios - 向 UITextField 添加下划线占位符

ios - 单击 UITextField 时显示自定义控件

iphone - 如何在 iphone 应用程序中验证 URL

ios - Swift 中的委托(delegate) - 错误无法使用参数列表调用 addTarget

swift - 如何在 CloudKit 上快速存储用户位置?

swift - 如何从另一个 ViewController 更改标签颜色? swift