Transparency through multiple views - ios

I have an icon image that is ontop of a UIView with a black color. I would like to be able to see the bottom view within the outline of the icon image.
Guessing CALayer is the way to go, just not too sure how to use it
Useful information
-Splash Screen Background = gray
-Splash Screen Size = view.frame.size
-Icon image size = 75 x 75
Thanks

If you are using the UIImageView for icon then set its alpha less than 1 i.e. 0.8 or 0.5 as you want the transparency.
Otherwise user the transparent image.

Related

How to add a border to an image rather than the image view?

I am building a "photo gallery" for my app. When a user taps on an image I want a blue border to appear (to show that it is selected). Since I am using the content mode .scaleAspectFit, the image almost never takes up the full image view resulting in this. I want the border to be just around the image itself like this (the red border). How would I accomplish this?
My code...
imageView.image = images[index]
imageView.contentMode = .scaleAspectFit
imageView.layer.borderColor = UIColor.blue.cgColor
imageView.layer.borderWidth = 5
imageView.clipsToBounds = true
Make the aspect ratio of the imageView equal to the aspect of the image [ by creating all images to be same aspect ratio ] and give the imageView screen width minus border width
You can't achieve that effect with features of a UIImageView. You will need to customize something and there are a lot of approaches that could achieve the effect you want.
One easy solution is to do that scaling yourself. Aspect fit is extremely easy to compute. Here is an example I found.
Once you have computed the scaled image size, set the frame of the UIViewView to that size. Now your image will take up 100% of the UIImageView and your border will align properly!

Blurred or transparent bottom of image

I need to add some effect to background image that will blurring the image in the bottom. Like here on background image :
Does someone know how to do it ?
That's not actually blurred, it's fading out to white. You can achieve this by putting a vertical gradient over the top of the image that goes from 100% opaque (alpha 1.0) white at the bottom to 0% opaque (alpha 0.0) white at the top.
There's a decent gradients tutorial here:
http://blog.apoorvmote.com/gradient-background-uiview-ios-swift/
Create a UIView with required CGRect and then add your UIImageView as subview to the UIView. Now set some gradient color to UIView, this way you can achieve your requirement.

Transparent text color in a Today View Widget

I'm trying to get the same color/transparent effect as Apple has used on the bottom borders of table view cells in the today view. How can I also use this effect on for example a UILabel?
How do you get the white transparent effect on a UILabel in a today view widget?
I've wondered the same myself. I think They're setting a color of white with 0.4 alpha on the font and a color of black with 0.4 alpha on the background. They overlay the whole thing over a gaussian-blurred and saturated image of what was previously behind the today view.
So the required steps to produce the same effect would be something like the following:
1. Grab background image
2. Blur and saturate image
3. Add below the current view
4. Set black background of 0.4 alpha and white font of 0.4 alpha on the current view.
If you can think of a way to make the background translucent right behind the font that would make the color show more.
Here's an image of what that would look like (including the translucent background behind the text). I did this real quick in photoshop, don't mind the font.
Hope this helps!

creating a gradient bar ios

How would I create a gradient bar so that when I pan over it I could change the color?
I could easily add a UIPanGestureRecognizer and get some translation within a UIView, but how would I change the RGB values of a UIColor appropriately?
Instead of using an RGB colour, I would use HSB. Just change the hue depending on the swipe.
If you treat the top of the screen as 0.0 and the bottom as 1.0, as the user swipes their finger from top to bottom, the colour should go through it's full spectrum. Then
CGFloat percentTranslation = currentY / self.view.bounds.size.height;
[UIColor colorWithHue:percentTranslation saturation:1.0 brightness:1.0 alpha:1.0]
I've done this before. The easiest way without doubt is to create a png image and use that.
You can calculate the per pixel colour but it's far quicker to just use an image.
In fact. I created a full colour picker which you can see in my app https://itunes.apple.com/gb/app/game-of-life/id477039315?mt=8
The colour bar in the 2nd screen shot is just a png. And the colour square uses a transparent image that has a black-transparent gradient bottom to top and a white-transparent gradient left to right.
All I do is set the background colour of the image view when the colour is selected on the bar.

iOS : Gradient semi transparent image overlay on

I need to make my scrollview to be transparent at top and bottom while the underneath text view could be scrolled like shown below.
I made one .png image in photoshop with gradient (black on top) and transparency at bottom.
When I added the image onto the Image view that is atop the scorllview, and run it on the simulator, the whole image is pure black and transparency gone.
Can someone please advise?
Set your imageView's background color to clear.
Also, wouldn't the image you need be white on bottom and transparent on top, rather than black on top and transparent on bottom?
My mistake... I have saved the image as JPG. not PNG. PNG is working properly. Thanks!

Resources