how to change dock icon using setContentView to display one big character in mac os x

删除回忆录丶 提交于 2019-12-23 04:54:16

问题


I want to change the dock icon of an app into one big character like an "A" or "B" for example using swift or objective C


回答1:


import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!

    @IBOutlet weak var dockView: NSView!
    @IBOutlet weak var dockText: NSTextField!
    let appDockTile =  NSApplication.sharedApplication().dockTile

    func prepareDock(){
        appDockTile.contentView = dockView
        appDockTile.display()
    }
    func changeText(){
        dockText.stringValue = "B"
         appDockTile.display()
    }
    func applicationDidFinishLaunching(aNotification: NSNotification) {
        // Insert code here to initialize your application
        prepareDock()

    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }

    @IBAction func btnChangeText(sender: AnyObject) {
        changeText()
    }

}



回答2:


my two cents for OSX swift 4.x:

(make it flash..)

...

self.HeartBeatTimer = Timer.scheduledTimer(withTimeInterval: DELTA_T, repeats: true, block: { (t: Timer) in

      let name = colored ? "heartbeat" : "heartbeat_red"
      let image = NSImage(named:  name)            
      let appDockTile =  NSApplication.shared.dockTile
      appDockTile.contentView = NSImageView(image: image!)
      appDockTile.display()
}


来源:https://stackoverflow.com/questions/27151788/how-to-change-dock-icon-using-setcontentview-to-display-one-big-character-in-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!