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

Why is my bottomText border not disabled but topText is working?

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

您设置了两次顶部文本边框样式。请检查您的底部文本代码。您没有在任何地方设置 bottomtext 的边框。