2017-09-16 84 views
1

我试图改变NSTextField的高度,与MacOS应用程序。如何更改NSTextField的高度?

如何更改我的NSTextField的高度,并让文字垂直居中,如iOS上的正常UITextField。我添加了一个高度限制,试图让它变大并且什么都不会改变。

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 
} 

} 

enter image description here

+0

为什么要设置一个属性串20.0字体大小的文本字段?我发现你的工作很不发达。 –

+0

为什么不在故事板中设置字体?这会自动调整文本字段的高度。 – Willeke

回答

-1

当你工作/使用XIB文件或故事板,你可以设置的NSTextField有本身的高度和对齐方式。如果约束不起作用,那么您可能没有正确设置它们,或者您错过了如何在Mac开发环境中工作。如果这是你是不是在找什么,然后问具体是,在何处以及如何做你想做也有助于解释,你这样做会帮助他人伸出援助之手,以你的工作。

BTW,iOS开发是苹果开发环境的子集。 Mac的开发要先进得多,并且有可用的Mac应用程序。

+2

“当你工作/使用XIB文件或故事板,你可以设置的NSTextField有本身的高度和定位。”告诉我们你是如何做到的。 –