Hello,
I am new to iPhone programming, but I have done Mac programming since around 2009. I created a new "Single View" project in Xcode for the iPhone and I am attempting (without success) to add a subview. I created a subclass of UIView and called it "DrawingView". This is my DrawingView.m code:
The goal was to have this view be red. In the standard view controller (the Xcode generated one) I add a field:
In the viewDidLoad: of the View controller I added this code (after [super viewDidLoad]):
When I run my app I get the standard gray screen
! Why does this code not yield a red screen?
Thanks!
I am new to iPhone programming, but I have done Mac programming since around 2009. I created a new "Single View" project in Xcode for the iPhone and I am attempting (without success) to add a subview. I created a subclass of UIView and called it "DrawingView". This is my DrawingView.m code:
Code:
#import "DrawingView.h"
@implementation DrawingView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setOpaque:YES];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextFillRect(context, self.frame);
};
@end
The goal was to have this view be red. In the standard view controller (the Xcode generated one) I add a field:
Code:
DrawingView *drawingView;
In the viewDidLoad: of the View controller I added this code (after [super viewDidLoad]):
Code:
CGRect screenBounds;
screenBounds = [[UIScreen mainScreen] bounds];
[drawingView initWithFrame:screenBounds];
[self.view addSubview:drawingView];
When I run my app I get the standard gray screen
Thanks!
Last edited: