- (void)viewDidLoad
{
[super viewDidLoad];
CustomView *customView = [[CustomView alloc] initWithFrame:CGRectMake(20, 20, 280, 200)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 270, 180)];
label.backgroundColor = [UIColor redColor];
[customView addSubview:label];
// customView.backgroundColor = [UIColor clearColor];
customView.backgroundColor = [UIColor blueColor];
[self.view addSubview:customView];
[customView release];
}
#import <UIKit/UIKit.h>
@interface CustomView : UIView
@end
#import "CustomView.h"
@implementation CustomView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, CGRectGetMidX(rect)-10, CGRectGetMaxY(rect)-15);
CGContextAddLineToPoint(ctx, CGRectGetMidX(rect), CGRectGetMaxY(rect));
CGContextAddLineToPoint(ctx, CGRectGetMidX(rect)+10, CGRectGetMaxY(rect)-15);
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, 1, 1, 0, 1);
CGContextFillPath(ctx);
}
@end