How do I show an image/icon on NSTabViewItem using swift macOS App in Xcode 13.2.1

129 Views Asked by At

step1. I new a project in Xcode 13.2.1 with macOS App, swift and storyboard

step2. The default NSViewController named ViewController

step3. I added a NSTabView on ViewController and I connected first NSTabViewItem to ViewController and select Outlet and named tab. I set tab.label and tab.image shown below.

class ViewController: NSViewController {
    @IBOutlet weak var tab: NSTabViewItem!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        tab.label = "Tab"
        tab.image = NSImage(named: "icon.png")
    }
}

step4. I run the App and the image(icon.png) didn't show.

I would like to show an image/icon on NSTabViewItem like picture below. (https://i.stack.imgur.com/f7Scv.png)

How do I show an image/icon on NSTabViewItem? Could you provide a sample code? Thanks a lot in advance.

0

There are 0 best solutions below