最初に CustomView を作成します。
#import <UIKit/UIKit.h>
@interface MyView : UIView
@end
#import "MyView.h"
@implementation MyView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing Rect
[[UIColor redColor] setFill]; // red
UIRectFill(CGRectInset(self.bounds, 100, 100));
}
@end
あなたがテストします。AppDelegate または ViewController へのリンク
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MyView* view = [[MyView alloc]initWithFrame:CGRectMake(10, 30, 300, 400)];
view.backgroundColor = [UIColor blackColor];
[window addSubview:view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)viewDidLoad
{
MyView* view = [[MyView alloc]initWithFrame:CGRectMake(10, 30, 300, 400)];
view.backgroundColor = [UIColor blackColor];
[self.view addSubview:view];
[super viewDidLoad];
}