มี 2 แบบ
1.จัดโดยใช้ Storyboard ช่วย
2.เขียนโค๊ดจัดการเอง
let dateView:NSStackView! = NSStackView() dateView.spacing = 1 dateView.distribution = .fill dateView.orientation = NSUserInterfaceLayoutOrientation.horizontal let dateUpload:NSText! = NSText() dateUpload.string = String(item.date) dateUpload.isEditable = false dateUpload.backgroundColor = NSColor(hex:"F7F7F7", alpha: 1.0) dateUpload.alignment = .center dateUpload.font = NSFont.boldSystemFont(ofSize: 16) dateView.addArrangedSubview(dateUpload) dateView.translatesAutoresizingMaskIntoConstraints = false dateUpload.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ dateUpload.widthAnchor.constraint(equalToConstant:200.0), dateUpload.trailingAnchor.constraint(equalTo:dateView.trailingAnchor,constant:0.0), dateUpload.heightAnchor.constraint(equalToConstant: 21.0), dateView.widthAnchor.constraint(equalToConstant:400.0), dateView.heightAnchor.constraint(equalToConstant: 50.0), ]) self.stack.addArrangedSubview(dateView)