
Mastering macOS Programming
By :

We will start with a simple custom button, which will serve as an uncomplicated first look into AppKit and Core Graphics.
We will design the view in a standard template macOS app, so create a new project and call it CoreGraphicsTest
or something. The name doesn't matter, since it's the classes that we design that we will use in other apps (whose names presumably do matter).
Drag a Custom View
object onto the View Controller Scene
, as illustrated in the following screenshot:
Set its Width
and Height
properties as 200
in the size inspector (command+ option + 5).
Before we start coding, let's take a look at what the finished result will look like:
To begin with, we'll create a class and make the Interface Builder custom view an instance of that.
Follow these steps:
ButtonView
, and make it a subclass of NSButton
.ButtonView
class in a file named ButtonView.swift...