我有一个名为RedDot的自定义视图,它在.m文件中有如下内容:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
//// Color Declarations
UIColor* fillColor = [UIColor colorWithRed: 0.886 green: 0 blue: 0 alpha: 1];
//// Oval Drawing
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(30, 30, 7, 7)];
[fillColor setFill];
[ovalPath fill];
[fillColor setStroke];
ovalPath.lineWidth = 1;
[ovalPath stroke];
}我试图用这段代码在主视图中调用它,但它不起作用:
RedDot *dot = [[RedDot alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 30.0f, 30.0f)];
[self.view addSubview:dot];编辑:
它只是在角落里显示了一个黑色的矩形。
发布于 2014-01-16 11:37:22
创建要绘制外部视图边界的bezier路径:
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(30, 30, 7, 7)];创建更大的视图或更改为您的圆圈,您应该看到您的绘图。
https://stackoverflow.com/questions/21160612
复制相似问题