如何为 UIView 创建半透明背景? [英] How do you create a semi-transparent background for a UIView?

查看:62
本文介绍了如何为 UIView 创建半透明背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 UIView,其中包含一些部分覆盖 UIImageView 的文本.我希望用户能够阅读文本并仍然保持对下面图像的透视.我已经尝试将背景颜色设置为 [UIColor clearColor],但是背景是完全透明的,根据图像颜色很难阅读文本.

I am creating a UIView containing some text that partially covers a UIImageView. I want the user to be able to read the text and still maintain a perspective on the image underneath. I have tried setting the background color to [UIColor clearColor], but then the background is totally transparent and it is hard to read the text depending upon the image colors.

如果我降低 view.alpha=0.5,包括文本在内的整个视图都是部分透明的.我想要的是保留文本并部分降低背景的透明度,让图像显示出来.

If I lower the view.alpha=0.5 the whole view including the text is partially transparent. What I'd like is to maintain the text and reduce the transparency of the background partially, allowing the image to show through.

推荐答案

我想你的意思是你想让你的 UIView 的 backgroundColor 是半透明的?如果您想要白色/透明,请使用:

I think what you mean is you want the backgroundColor of your UIView to be semi transparent? If you want white/transparent use this:

myView.backgroundColor = [UIColor colorWithWhite:myWhiteFloat alpha:myAlphaFloat];

否则,如果您希望它是另一种颜色,请使用通用的 UIColor 方法:+colorWithRed:green:blue:alpha:

else if you want it to be another color use the general UIColor method: +colorWithRed:green:blue:alpha:

这篇关于如何为 UIView 创建半透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆