为视图设置 2 个不同的背景
我有一个观点,它分为两部分。在视图的上半部分我想要一个蓝色背景,在下半部分我想要一个透明背景。我不确定是否可以做到。 任何建议将不胜感激。谢谢
I have a view, which is divided into 2 parts. On the top half of the view I want a blue background and on the bottom half I want a transparent background. I am not sure if it can be done.
Any suggestions will be appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以做到这一点。到目前为止,最简单的方法是在视图的上半部分创建一个具有蓝色背景的子视图。其他方法包括添加子图层或使用自定义绘图代码覆盖
drawRect
。There are multiple ways to do this. By far the easiest is to simply create a subview in the top half of the view with a blue background. Other methods include adding a sublayer or overriding
drawRect
with custom drawing code.如果您只想创建一个视图,那么您必须创建一个包含 2 部分的图像文件
,上半部分是蓝色,下半部分是透明的,
否则您需要创建两个具有不同背景的视图
if you only want to create a single view then you have to create a image file with 2 parts
upper part is blue and bottom half is transparent
else you need to create two view with different background