Determinate spinning NSProgressIndicator doesn't adapt to frame size and gets cut off

The following code should produce 6 spinning progress indicators of varying sizes: 3 indeterminate and 3 determinate ones. The first two of the 3 determinate ones are either entirely or partially cut off, which doesn't happen with the indeterminate ones. What's the problem?

var progress = NSProgressIndicator(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
progress.style = .spinning
view.addSubview(progress)

progress = NSProgressIndicator(frame: CGRect(x: 50, y: 0, width: 24, height: 24))
progress.style = .spinning
view.addSubview(progress)

progress = NSProgressIndicator(frame: CGRect(x: 100, y: 0, width: 32, height: 32))
progress.style = .spinning
view.addSubview(progress)

progress = NSProgressIndicator(frame: CGRect(x: 150, y: 0, width: 16, height: 16))
progress.style = .spinning
progress.isIndeterminate = false
progress.doubleValue = 50
progress.maxValue = 100
view.addSubview(progress)

progress = NSProgressIndicator(frame: CGRect(x: 200, y: 0, width: 24, height: 24))
progress.style = .spinning
progress.isIndeterminate = false
progress.doubleValue = 50
progress.maxValue = 100
view.addSubview(progress)

progress = NSProgressIndicator(frame: CGRect(x: 250, y: 0, width: 32, height: 32))
progress.style = .spinning
progress.isIndeterminate = false
progress.doubleValue = 50
progress.maxValue = 100
view.addSubview(progress)
Answered by DTS Engineer in 761755022

NSProgressIndicator is not arbitrarily resizable. (It might have been, for these indicator shapes, in the past, but I don't remember any details.) Nor is it necessarily a good assumption that a 1:1 aspect ratio (frame width == frame height) is appropriate for the view.

My recommendation is that you create a default indicator using NSProgressIndicator, then choose a standard size by setting the controlSize property to one of the standard values. If necessary, use auto layout constraints relative to the containing view, or relative to the sibling views in the same container, to make sure that there's a suitable margin around the control for the chosen size.

Accepted Answer

NSProgressIndicator is not arbitrarily resizable. (It might have been, for these indicator shapes, in the past, but I don't remember any details.) Nor is it necessarily a good assumption that a 1:1 aspect ratio (frame width == frame height) is appropriate for the view.

My recommendation is that you create a default indicator using NSProgressIndicator, then choose a standard size by setting the controlSize property to one of the standard values. If necessary, use auto layout constraints relative to the containing view, or relative to the sibling views in the same container, to make sure that there's a suitable margin around the control for the chosen size.

Determinate spinning NSProgressIndicator doesn't adapt to frame size and gets cut off
 
 
Q