将全屏按钮设置为+,只能铺满屏幕
self.window?.collectionBehavior = NSWindow.CollectionBehavior.fullScreenAuxiliary
设置NSMenuItem字体颜色
menuitem.attributedTitle = NSAttributedString(string: delete_menuitem.title, attributes: [NSAttributedStringKey.foregroundColor: NSColor.red, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 14)])
播放mp3
import AVFoundation
import MediaPlayer
var audioPlayer: AVAudioPlayer?
let path = Bundle.main.path(forResource: "g_002", ofType: "mp3")
let pathURL = NSURL(fileURLWithPath: path!)
do {
audioPlayer = try AVAudioPlayer(contentsOf: pathURL as URL)
} catch {
audioPlayer = nil
}
audioPlayer?.prepareToPlay()
audioPlayer?.play()
NSTextView 边距
ContentTextView.textContainerInset = NSSize(width: 10, height: 10)
NSTextView行间距
extension DueWindowController: NSTextStorageDelegate {
override func textStorageDidProcessEditing(_ notification: Notification) {
let pa = NSMutableParagraphStyle()
pa.lineSpacing = 5 //间距值
let attributes = [NSAttributedStringKey.font:NSFont.systemFont(ofSize: 20),NSAttributedStringKey.paragraphStyle: pa]
let attr = NSMutableAttributedString(string: self.ContentTextView.string, attributes: attributes)
self.ContentTextView.textStorage?.setAttributedString(attr)
}
}
去掉NSScrollView的ScrollerBar
class NoBarScrollView: NSScrollView {
override func tile() {
super.tile()
var hf = self.horizontalScroller?.frame
hf?.size.height = 0
self.horizontalScroller?.frame = hf!
var vf = self.verticalScroller?.frame
vf?.size.width = 0
self.verticalScroller?.frame = frame
}
}