简体   繁体   中英

How to change the height of a NSTextField?

I am trying to change the height of a NSTextField for a macOS application.

How can I change the height of my NSTextField and have the text centered vertically like a normal UITextField on iOS. I added a height constraint to try and make it bigger and nothing will change.

class LoginVC: NSViewController {

@IBOutlet weak var emailField: TF!
@IBOutlet weak var passwordField: STF!

override func viewDidLoad() {
    super.viewDidLoad()

    emailField.usesSingleLineMode = true
    emailField.placeholderAttributedString = NSAttributedString(string: "Email", attributes: [NSForegroundColorAttributeName: NSColor.lightGray, NSFontAttributeName: NSFont(name: "Menlo", size: 20)!])
    emailField.alignment = .center

    passwordField.usesSingleLineMode = true
    passwordField.placeholderAttributedString = NSAttributedString(string: "Password", attributes: [NSForegroundColorAttributeName: NSColor.lightGray, NSFontAttributeName: NSFont(name: "Menlo", size: 20)!])
    passwordField.alignment = .center
}

override func viewWillAppear() {
    super.viewWillAppear()

    view.layer?.backgroundColor = EYE_GREY.cgColor
}

}

在此处输入图片说明

As you are working on/using XIB files or storyboards you can set the height and alignment of the NSTextField there itself. If the constraints are not working then you might have not set them up properly or you are missing on how to work in Mac development environment. If this is what you are not looking then ask specifically, where and how do you want help also explain the work that you did that will help others to lend a helping hand to you.

BTW, iOS development is the subset of Mac development environment. Mac development is far more advanced and there are/were awesome Mac applications available out there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM