이것은 어떻게 생겼는가? 나는 검은 배경을 맑게하고 싶지 않고 그것을 알아낼 수 없다.왜 "initi 프레임"이 검은 색으로 변하는가? initwithframe으로 CGRect 둥근 모서리 그리기
이- (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);
}
코드가 함께 둥근 상자를 그립니다 내가 miniC에서 전화의 drawRect 곳
다음loadView { CGRect frame = CGRectMake(screenWidth - OFFSET, DEFAULT_PADDING, 140, 40); miniC* mcView = [ [ [miniC alloc] initWithFrame:frame] autorelease]; mcView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; [[self view] addSubview:mcView]; }
은 다음과 같습니다
는에는 loadView입니다 찾고있는 획이지만 새로운 둥근 b 뒤에는 블랙 박스가 있습니다. 소. 나는 여러 가지 다른 것들을 시도했지만 배경색을 분명하게 만드는 방법을 알아낼 수 없습니다. 또한 QuartzCore로이 작업을 수행 할 수 있다는 것을 알고 있지만 원하지 않습니다.P. 나는 객관적으로 새로운 c 다.
EDIT :
공극 roundCorners (CGContextRef 컨텍스트 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 -
걸고 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));
}
무효 fillBackgroundColor (CGContextRef 컨텍스트, CGRect의 RECT, CGColorRef bgColor가) {
CGContextSetFillColorWithColor(context, bgColor); CGContextFillRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height));
}
뷰를 불투명하게 만드는 것을 기억 했는가? –
분명히하지 않았습니다. 내가 이것을 어디에서 설정할 것입니까? – morcutt
'mcView.opaque = NO'를 loadView에 추가하면 그 내용을 확인할 수 있습니다. 그리고 그 것이 유일한 문제라면, 그것을 Paul의 initWithFrame으로 이동하십시오. 너를 위해 썼다. –