2012-03-06 2 views
20

와 하위 뷰 본인은 서브 뷰는 부모의 알파 값을 상속하는 것 1.보기 - 높은 알파

의 알파와 하위 뷰를 추가 한 0.5 의 알파와 UIView 있습니다. 하위보기를 부모보기보다 불투명하게 만드는 방법이 있습니까?

코드는 다음과 같습니다

CGRect promptFrame = CGRectMake(55, 80, 180, 50); 
UIView *inputPrompt = [[UIView alloc] initWithFrame: promptFrame]; 
[inputPrompt setBackgroundColor: [UIColor darkGrayColor]]; 
[inputPrompt setAlpha: .5]; 
inputPrompt.layer.cornerRadius = 8; 
inputPrompt.layer.masksToBounds = YES; 

CGRect fileTextFieldFrame = CGRectMake(10, 15, 150, 25); 
UITextField *filePrompt = [[UITextField alloc] initWithFrame: fileTextFieldFrame]; 
[filePrompt setBorderStyle:UITextBorderStyleRoundedRect]; 
[filePrompt setClearButtonMode:UITextFieldViewModeWhileEditing]; 
[filePrompt setBackgroundColor: [UIColor whiteColor]]; 
[filePrompt setAlpha: 1]; 

결과는 다음과 같습니다 enter image description here

내가 아닌 흰색 UITextField 아래 회색 UIView 아래 버튼을 볼 수 있도록하고 싶습니다. 어떻게해야합니까?

답변

79

inputPrompt의 배경색은 알파가 아닌 알파를 직접 설정하십시오.

[inputPrompt setBackgroundColor:[[UIColor darkGrayColor] colorWithAlphaComponent:0.5]]; 
//[inputPrompt setAlpha: .5]; 
+1

제대로 작동했습니다. 감사. – StoneBreaker

+1

+1 그리고 고맙습니다. :) – Sarah

+1

+1 매우 잘 작동합니다. –