DanM
DanM

Reputation: 141

NSView alpha on viewDidLoad doesn't display

I have a custom NSView which I set the isEnabled flag in viewDidLoad but it is not displaying at 0.5 alpha, even though isEnabled is correctly set and the correct code is called in drawRect for the custom view.

As soon as I click a text field in the same view controller the view alpha changes.

Here is the code called in viewDidLoad

        forceOutput.isEnabled = true

And here is the code called by drawRect

        // is the view enabled?
    if isEnabled {

        // alpha should be full (opaque)
        self.alphaValue = 1.0

    } else {

        // make the view slightly transparent
        self.alphaValue = 0.5
    }

Upvotes: 1

Views: 176

Answers (1)

Rob
Rob

Reputation: 437692

Setting alpha in drawRect is generally too late in the rendering process. If setting alpha, do it before drawRect is called. Perhaps set the alpha in viewDidLoad. Or, better, have a didSet for the isEnabled property that sets the alpha. But don't do it in drawRect, itself.

Upvotes: 1

Related Questions