jpswain
jpswain

Reputation: 14732

UIBezierPath outline keeps appearing around view for some reason

This code below is what I use to create my subview, "theSubview", which I add to the parent view "parentView".

Say parentView has the frame { {0.0, 0.0}, {100.0, 100.0} } and theSubview has the frame { {20.0, 20.0}, {20.0, 20.0} }

The problem is that when my drawing is done, I end up with not only the blue arrow mark, but also a blue outline that is on the frame of theSubview.

Any ideas what I'm doing wrong?

Thanks!



// 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];


}

Upvotes: 0

Views: 337

Answers (1)

jpswain
jpswain

Reputation: 14732

Duh, I figured it out. The bezierPathWithRect actually makes a bezierPath with that rect as a path. The rect is not a frame, b/c bezierPath has no frame.. b/c it's not a UIView.

Changing my above code to

UIBezierPath *arrowPath = [UIBezierPath bezierPath];

fixes it.

Upvotes: 1

Related Questions