カスタムビューを描画したいのですが、次のようにしています:
#import <UIKit/UIKit.h>
@interface CustomView : UIView
/** The color used to fill the background view */
@property (nonatomic, strong) UIColor *drawingColor;
@end
#import "TocCustomView.h"
#import "UIView+ChangeSize.h"
@interface CustomView()
@property (nonatomic, strong) UIBezierPath *bookmarkPath;
@end
static CGFloat const bookmarkWidth = 20.0;
@implementation CustomView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect{
[[UIColor blueColor] setFill];
[[self bookmarkPath] fill];
}
- (UIBezierPath *)bookmarkPath{
if (_bookmarkPath) {
return _bookmarkPath;
}
UIBezierPath *aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(self.width, self.y)];
[aPath moveToPoint:CGPointMake(self.width, self.height)];
[aPath moveToPoint:CGPointMake(self.width/2, self.height-bookmarkWidth)];
[aPath moveToPoint:CGPointMake(self.x, self.height)];
[aPath closePath];
return aPath;
}
@end
そして、私はこのようなコントローラーでビューを使用しています:
CGRect frame = CGRectMake(984, 0, 40, 243);
CustomView *view = [[CustomView alloc] initWithFrame:frame];
view.drawingColor = [UIColor redColor];
[self.view addSubview:view];
長方形の描画がうまくいかない問題!! 結果は黒い長方形です。私は何を間違っていますか?