Glass effects UIView

2019-04-13 14:50发布

问题:

I would like to know how it is possible to add a glass effect on a UIView

I would like something like this effects on the gray translucent view you can see here :

Thanks

回答1:

There's nothing like glass effect in UIView .All you can do is set the opacity of the view between 0 and 1.Also the view shown above has fine set of images which makes it seem like your "Glass Effect".

Well If you what your UIView to be "shiny and elegant" , you can do it in two ways :-

1>You can simply have effects in images created with photoshop as it will decrease the overhead of doing the same with programming.

2>you can have it using core-Graphics library provided by apple then you might have to get into a more complex world of drawing and see the Tutorial to get Gloss Effect

Glossy Buttons By Ray wendelich

Another Tutorial on Glossy button



回答2:

There's a pretty cool Mac app called PaintCode, that allows you to create your glossy/glass effects in a similar way to Photoshop, say, but then generates the code you can add you your app. They give some examples here: http://www.paintcodeapp.com/examples.html



回答3:

There is no trivial way to achieve this with a UIView, but of course it can be done, in the way that all graphics work can be done: Setup a drawing context and draw your effect using CoreGraphics in your views drawRect method.

If you're curious, I recommend you take a look at an application called Opacity. It is a simple graphics editor for Mac OS - and allows you to work on a visual canvas and apply effects, including, amongst others, a 'glass' filter. The distinguishing feature of this app is that it will generate backing Quartz code for what you've designed visually with its GUI.

The code it generates may or may not be sufficient for what you're seeking, but I use it routinely to generate rough drawing code that I can then look at as a basis to put together my own drawing code.

I have no affiliation with this product beyond the fact that I use it.



回答4:

I guess you need a glossy effect in your UIView. This can be achieved by setting the alpha mask of your UIView and adjusting the backgroundcolor to a little darker in the drawrect method of your UIView. If this doesnt satisfy your needs, you can go for a more comprehensive solution outlined by Matt Galagher