2011-03-08 3 views
4

알파와 레이블이있는 UIView를 만들고 싶습니다.UIlabel이 앞에있는 알파 UI보기 만들기

enter image description here

하지만 난 이런 모든 앞에있는 UILabel의 원하는 :

enter image description here

은 어떻게 할 수 있나요? 여기

코드 :

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.view.backgroundColor = [UIColor redColor]; 

    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 200, 20)]; 
    lbl.text = @"AAAAAA"; 
    lbl.backgroundColor = [UIColor clearColor]; 

    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(50, 210, 230, 50)]; 
    v.backgroundColor = [UIColor greenColor]; 
    v.alpha = 0.5; 
    [v addSubview:lbl]; 

    [self.view addSubview:v]; 

} 

녹색보기 텍스트처럼 ... 알파 0.5 함께이 잘못이다!

감사합니다.

답변

13

전체보기의 알파를 설정하는 대신 배경색을 투명도가있는 색상으로 설정하면됩니다.

그래서이를 변경 :

v.backgroundColor = [UIColor greenColor]; 
v.alpha = 0.5; 

을이 사람 :

v.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.5]; 
+1

P-E-R-F-E-C-T !!! 덕분에 – elp

+0

하지만 왜 작동합니까 ??? – elp

+0

@ Paska 전체보기의 알파를 설정하면 Label이 해당보기의 일부이므로 알파도 설정됩니다. 보기의 배경색 알파를 설정하면 레이블에는 영향을주지 않습니다. – theChrisKent

2

당신이 색상에 내장 된 사용하려면, colorWithAlphaComponent 참조 : 엑스 코드 4 인터페이스에서

accessoryView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.4]; 
0

을 빌더를 사용하면보기의 Background 속성을 클릭하고 "Other"를 클릭 한 다음 색상 및 불투명도 값이 표시됩니다.

관련 문제