2011-04-25 2 views
0

트리거 할 수 없습니다CGGradient는 (인터페이스 빌더를 사용하지 않는) 표시되지 및 UIButtons 내가 CGGradient을 포함하는 뷰를 만든

// Bar ContextRef 
CGRect bar = CGRectMake(0, screenHeight-staffAlignment, screenWidth, barWidth); 
CGContextRef barContext = UIGraphicsGetCurrentContext(); 
CGContextSaveGState(barContext); 
CGContextClipToRect(barContext,bar);  

// Bar GradientRef 
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
CGFloat components[16] = { 1.0,1.0,1.0,0.0, 0.0,0.0,0.0,1.0, 0.0,0.0,0.0,1.0, 1.0,1.0,1.0,0.0}; 
CGFloat locations[4] = {0.95,0.85,0.15,0.05}; 
size_t count = 4; 
CGGradientRef gradientRef = CGGradientCreateWithColorComponents(colorSpace, components, locations, count); 

// Draw Bar 
CGPoint startPoint = {0.0,0.0}; 
CGPoint endPoint = {screenWidth,0.0}; 
CGContextDrawLinearGradient(barContext, gradientRef, startPoint, endPoint, 0); 
CGContextRestoreGState(barContext);  

이 코드는 UIView의의의 drawRect 방법이라고합니다. 그런 다음 UIViewController를 사용하여 만든 뷰에 액세스합니다.

- (void)loadView { 

MainPageView *mpView = [[MainPageView alloc] initWithFrame:[window bounds]]; 
[self setView:mpView]; 
[mpView release]; 

}

및 AppDelegate에 통해 화면에 표시 :

mpViewController = [[MainPageViewController alloc] init]; 
[window addSubview:[mpViewController view]]; 

[window makeKeyAndVisible]; 

의 UIView이 가시 같은 UIButtons 자세히 물체를 포함한다. 하위 뷰로 추가되기 때문에 가정합니다. 하지만 하위 뷰로 CGGradient를 추가하는 방법을 알아낼 수 없습니까? 그럴 필요가 있습니까? CGGradient가 보이지 않는 다른 이유가 있습니까?

UIButton에도 기능이 없습니다. UIButtons를 뷰에 추가 한 이유가 여기에 있습니다. 기능을 사용하려면 버튼을 UIViewController 또는 appDelegate에 추가해야합니다. 미안하지만 간단한 질문처럼 보일지는 모르겠지만 인터페이스 빌더가 없으면 프로그래밍을 완료하려고하는데 그 재료가 부족합니다. 누군가가이 두 가지 문제에 대해 올바른 방향으로 나를 지적 할 수 있다면 정말 감사 할 것입니다.

감사합니다.

답변

1

프레임이 너무 커서 단추가 여전히 보이기 때문에 단추의 기능이 손실되었습니다. 배경색이 투명하기 때문에 단추를 계속 사용할 수 있습니다.

관련 문제