下面的代码是我用来创建我的子视图“theSubview”,我将其添加到父视图“parentView”。
假设parentView的框架为{{0.0,0.0},{100.0,100.0}} andSubview具有框架{{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];
}
答案 0 :(得分:1)
将我的上述代码更改为
UIBezierPath *arrowPath = [UIBezierPath bezierPath];
修复它。