我有一个iPhone应用程序,在其中单击按钮会显示一个类似于alertview的视图。那时我希望剩余的视图(背景)成为阴影,就像我们在显示alertview时看到的背景一样。帮助我实现这一目标?
这相当简单,将新视图设为覆盖全屏的视图的子视图,并将alpha设置为0.7或您选择的颜色,然后呈现此视图,并且后面的所有内容都应变暗。
您可以只分配带有主视图框架的视图,并将背景色设置为灰色,当您单击按钮时,添加此视图然后添加指定的视图,或者可以在此灰色视图中添加指定的视图。
You can simply add a UIView as a subview of your controller view. Set black as the backgroundColor of it with an alphaValue between 0 and 1. Remember to set the frame equals to the viewcontroller view
In your alertview callback, just remove the view.
When a button click for showing a view:
-(void)yourButtonAction
{
[self.view setAlpha:0.3];
}
Now when removing view like an alertview.
[self.view setAlpha:1.0];
最好的方法是创建一个新图像(黑色半透明背景补丁),并添加超级视图的背景并将超级视图的背景色设置为clearcolor。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.