ryantuck
ryantuck

Reputation: 6644

Custom view not displaying when attempting to change background color

This is my first mac application. I've written for iOS before and have been able to accomplish this same goal.

I'm trying to change the background color of a custom view. In the photo below, the two views are named view0 and view1.

Here's the code I'm trying to use to accomplish this (in the AppDelegate.m file):

- (IBAction)upPressed:(id)sender {
    NSLog(@"upPressed");

    self.view0.layer.backgroundColor = CGColorCreateGenericRGB(1, 0, 0, 1);
}

I'd like the color of view0 to turn red upon pressing the up button. The button click registers fine.

When I run the simulator, the views do not even show up.

Upon clicking the up button, nothing changes.

Why is this single line of code inadequate? In iOS, I was able to use a similar method of setting the background color of a view to simply make its color change.

enter image description here

Upvotes: 2

Views: 237

Answers (1)

trueinViso
trueinViso

Reputation: 1394

Select the custom view and then select the 'Show View Effects Inspector' in the right pane (looks like 3 pieces of paper on top of each other in Utilities Window). Check the box next to Custom View under Core Animation Layer. This will enable the Core Animation for that view type.

Xcode

Upvotes: 1

Related Questions