UIView をサブクラス化するクラスを作成しました。drawRect には、オレンジ色の四角形を描画する必要があります。それでも黒く映ります。
私のカスタムクラスでは:
#import "testRect.h"
@implementation testRect
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(CGRect)rect
{
//// Color Declarations
UIColor* strokeColor = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 1];
UIColor* fillColor2 = [UIColor colorWithRed: 0.886 green: 0.59 blue: 0 alpha: 1];
//// Rectangle Drawing
UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(26.5, 171.5, 265, 139)];
[fillColor2 setFill];
[rectanglePath fill];
[strokeColor setStroke];
rectanglePath.lineWidth = 1;
[rectanglePath stroke];
}
そして私のビューコントローラー
#import "ViewController.h"
#import "testRect.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
testRect *test = [[testRect alloc] initWithFrame:CGRectMake(10, 10, 265, 139)];
[self.view addSubview:test];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end