下面的这段代码是我用来创建我的子视图“theSubview”的,我将它添加到父视图“parentView”中。
说 parentView 有框架 { {0.0, 0.0}, {100.0, 100.0} } 和 theSubview 有框架 { {20.0, 20.0}, {20.0, 20.0} }
问题是,当我的绘图完成后,我不仅得到了蓝色箭头标记,而且在子视图的框架上还有一个蓝色轮廓。
任何想法我做错了什么?
谢谢!
// theSubview
// My UIView subclass that is added to another view
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
}
return self;
}
- (void)drawRect:(CGRect)rect {
[self drawArrow];
}
- (void)drawArrow {
CGRect arrowRect;
arrowRect = self.bounds;
UIBezierPath *arrowPath = [UIBezierPath bezierPathWithRect:arrowRect];
// UIColor *backgrColor = [UIColor grayColor];
// [backgrColor setFill];
// [arrowPath fillWithBlendMode:kCGBlendModeNormal alpha:0.9f];
UIColor *strokeColor = [UIColor blueColor];
[strokeColor setStroke];
CGFloat thirdOfWidth = floorf(CGRectGetWidth(self.bounds) / 3);
CGFloat thirdOfHeight = floorf(CGRectGetHeight(self.bounds) / 3);
[arrowPath moveToPoint:CGPointMake(thirdOfWidth, thirdOfHeight)];
[arrowPath addLineToPoint:CGPointMake(thirdOfWidth * 2, thirdOfHeight + (floorf(thirdOfHeight/2)))];
[arrowPath addLineToPoint:CGPointMake(thirdOfWidth, thirdOfHeight * 2)];
[arrowPath setLineWidth:3.0f];
[arrowPath stroke];
}