0

下面的这段代码是我用来创建我的子视图“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];


}

4

1 回答 1

1

呃,我想通了。bezierPathWithRect实际上以该矩形作为路径创建了一个 bezierPath。矩形不是框架,b/c bezierPath 没有框架.. b/c 它不是 UIView。

将我上面的代码更改为

UIBezierPath *arrowPath = [UIBezierPath bezierPath];

修复它。

于 2013-03-04T05:33:48.590 回答