[英]Putting UIView with alpha 1 on top of UIView with alpha 0.5
[英]Set alpha of a portion of a UIView
當用戶點擊SearchBar時,我需要使視圖的矩形部分變黑。 我想不通一種方法。 我嘗試了CGRectMake,但如何設置該矩形的Alpha?
為什么不添加另一個UIView
並將其添加到某個事件的UIView
上?
可以通過以下方式將子層添加到視圖層中來完成
UIView * view = [[[[UIView alloc] initWithFrame:CGRectMake(50.0,0.0,100.0,100.0)]自動釋放]; view.backgroundColor = [UIColor grayColor]; [self.view addSubview:view];
CALayer *layerUP = [CALayer layer];
[layerUP setFrame:CGRectMake(0.0, 0.0, 100.0, 50.0)];
[layerUP setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0].CGColor];
[view.layer addSublayer:layerUP];
CALayer *layerDown = [CALayer layer];
[layerDown setFrame:CGRectMake(0.0, 50.0, 100.0, 50.0)];
[layerDown setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.2].CGColor];
[view.layer addSublayer:layerDown];
添加黑色背景的UIImageView:
UIImageView *myView= [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
myView.backgroundColor = [UIColor blackColor];
[self.view addSubview:myView];
[myView release];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.