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

1.6k views Asked by At

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

2

There are 2 answers

3
Leo Dabus On BEST ANSWER
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()
    }

}
0
ingconti On

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()
}