You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

// Copyright © 2015 Abhishek Banthia
extension NSTextField {
func applyDefaultStyle() {
backgroundColor = NSColor.clear
isEditable = false
isBordered = false
allowsDefaultTighteningForTruncation = true
isAutomaticTextCompletionEnabled = false
allowsCharacterPickerTouchBarItem = false
}
6 years ago
func disableWrapping() {
usesSingleLineMode = false
cell?.wraps = false
cell?.isScrollable = true
}
}
extension NSFont {
3 years ago
func size(for string: String, width: Double, attributes: [NSAttributedString.Key: AnyObject]) -> CGSize {
let size = CGSize(width: width,
height: Double.greatestFiniteMagnitude)
6 years ago
var otherAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.font: self]
6 years ago
6 years ago
attributes.forEach { arg in let (key, value) = arg; otherAttributes[key] = value }
6 years ago
return NSString(string: string).boundingRect(with: size,
options: NSString.DrawingOptions.usesLineFragmentOrigin,
attributes: attributes).size
}
}