[英]Create UIView with custom shape
So I was wondering if there's a way to make a UIView with a custom shape. 所以我想知道是否有一种方法可以制作具有自定义形状的UIView。
I'm trying to make a piano keyboard so when the user touches the view a delegate method responds by playing a noise. 我正在尝试制作一个钢琴键盘,以便当用户触摸视图时,委托方法会通过发出噪音来响应。 The picture is a .png with the picture of the key and a transparent background. 图片为.png文件,带有按键图片和透明背景。
Thanks in advance. 提前致谢。
You can't make a UIView
in the shape of, say, a triangle, but what you can do is make the view transparent, then add your non-transparent content to it. 您不能将UIView
做成三角形的形状,但是可以做的是使视图透明,然后向其中添加非透明内容。
For example , to make a view with a background of a png (with, I assume, partially transparent areas) you could make a transparent UIView
and then add an image view to it. 例如 ,要使视图具有png背景(我假设具有部分透明的区域),可以制作透明的UIView
,然后向其添加图像视图。 better yet , just use a UIImageView
in the place. 更好的是 ,只需在该位置使用UIImageView
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.