This is what it looks like. I want to make the black background Clear and can't seem to figure it out.
Here is the loadView:
loadView { CGRect frame = CGRectMake(screenWidth - OFFSET, DEFAULT_PADDING, 140, 40); miniC* mcView = [ [ [miniC alloc] initWithFrame:frame] autorelease]; mcView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; [[self view] addSubview:mcView]; }
Here is where I drawRect I call in miniC:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
// Set Background Color & Border Color
CGColorRef bgColor = [UIColor scrollViewTexturedBackgroundColor].CGColor;
CGColorRef borderColor = [UIColor grayColor].CGColor;
CGRect Rect = self.bounds;
// Round Corners
roundCorners(context, Rect);
// Fill with bgcolor
fillBackgroundColor(context, Rect, bgColor);
// Add 1 px stroke
CGRect strokeRect = Rect;
strokeRect.size.height -= 1;
strokeRect = (strokeRect);
CGContextSetStrokeColorWithColor(context, borderColor);
CGContextSetLineWidth(context, 1.0);
CGContextStrokeRect(context, strokeRect);
// Overlay Rect to Tint "scrollViewTexturedBackgroundColor" UIColor
CGContextRef secondContext = UIGraphicsGetCurrentContext();
// Set Background Color & Border Color
CGColorRef obgColor = [UIColor colorWithRed:255/255 green:255/255 blue:255/255 alpha:.3].CGColor;
// Round Corners
roundCorners(context, Rect);
// Fill with bgcolor
fillBackgroundColor(secondContext, Rect, obgColor);
}
The code draws the the rounded box with a stroke I am looking for but there is a black box behind the new rounded box. I've been trying a bunch of different stuff but can't seem to figure out how to make the background color clear. Also, I am aware I could do this with QuartzCore but I do not want to.
P.S. I am new to objective-c.
EDIT:
void roundCorners(CGContextRef context, CGRect rect) {
CGContextClearRect(context, rect); CGFloat c = INSET + CORNER_RADIUS; CGContextMoveToPoint(context, INSET, c); CGContextAddArcToPoint(context, INSET, INSET, c, INSET, CORNER_RADIUS); CGContextAddLineToPoint(context, rect.size.width - c, INSET); CGContextAddArcToPoint(context, rect.size.width - INSET, INSET, rect.size.width - INSET, c, CORNER_RADIUS); CGContextAddLineToPoint(context, rect.size.width - INSET, rect.size.height - c); CGContextAddArcToPoint(context, rect.size.width - INSET, rect.size.height - INSET, rect.size.width - c, rect.size.height -
INSET, CORNER_RADIUS); CGContextAddLineToPoint(context, c, rect.size.height - INSET);
CGContextAddArcToPoint(context, INSET, rect.size.height - INSET, INSET, rect.size.height > - c, CORNER_RADIUS); CGContextClosePath(context); CGContextClip(context); CGContextSetFillColorWithColor(context, [UIColor scrollViewTexturedBackgroundColor].CGColor); CGContextFillRect(context, CGRectMake(0, 0, rect.size.width - INSET, rect.size.height - INSET));
}
void fillBackgroundColor(CGContextRef context, CGRect rect, CGColorRef bgColor) {
CGContextSetFillColorWithColor(context, bgColor); CGContextFillRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height));
}