How to achieve this effect in iPhone SDK? - ios

I would like to how can I apply this effect in iPhone SDK?
So, I have an image and a label on top of it.
I want to have the effect in which the bottom portion kind of blends in with the image.
So that there is no clear demarcation from where the image ends at the bottom portion of the view.
Please let me know.

Easy way to achieve this to CAGradientLayer
UIView *yourGradientView; // with that label "ENTREES", Add this view as a subview of the background view.
CAGradientLayer *gradientLayer=[CAGradientLayer layer];
[gradientLayer setFrame:[yourGradientView bounds]];
[gradientLayer setColors:#[(id)[UIColor clearColor].CGColor, (id)[[UIColor whiteColor] colorWithAlphaComponent:0.7f].CGColor]];
[gradientLayer setLocations:#[[NSNumber numberWithFloat:0.50f], [NSNumber numberWithFloat:1.0f]]];
[[yourGradientView layer] insertSublayer:gradientLayer atIndex:0];

Easiest solution: Add UIImageView with gradient PNG image as a subview between the image and label if you have the constant color.
If you need variable color of the gradient, you can either add a subview with the gradient drawn using CoreGraphics or CALayer.
If you need the image to blend with any background, you can mask the background image layer with CALayer gradient layer.

Unless you provide any more details to your question with regards to functionality and some code, the first look instance seems to have the following solution:
Step 1
Set a UIImage as a background image. In your case it is the one shown in the question.
Step 2 add a UILabel as a subview of UIImage and set the background of UILabel to be transparent. Position the label as per your needs which in your case seems to be the bootom left.
Hope his helps !!!

Related

How can I make my text from "drawInRect" above the gradient layer?

I created a new class named MySegment which inherits from UIControl.
First, I initialized a gradient line with CAGradientLayer.
Second,[self.layer addSublayer:myLayer]
Then, ["myString" drawInRect:rect withAttributes:attributes] is in the same location.
I want the text from drawInRect to be overlaid on myLayer, but no matter what I use addSublayer or insertlayer,my text is always under mylayer, the effect is shown on the photo.
How can I make my text above the gradient layer?
I'd indeed use CATextLayer as #DonMag has pointed out. In that case, you would have CATextLayer and CAGradientLayer.
First insert the CAGradientLayer using addSubLayer
[self.layer addSubLayer:gradientLayer];
Then the CATextLayer using insertSubLayer:above:
[self.layer insertSubLayer:textLayer above:gradientLayer];
PS: Answered question about putting attributedstring in CATextLayer:
Displaying an attributed string in a CATextLayer

Make a white label visible on top of bright image view

Basic issue:
I believe the trick is with masking, but I am not able to get a good hold of how this is set.
Basically I have a bright image (set to a uiimageview object), and I have a label at very bottom (which is added on top of the image view) needs a well readable white text on it. Right now, the white text is hard to read (because of the bright background).
What I am doing:
I am setting a mask for the image view with something like
http://cl.ly/image/0i0N1p271d42
maskContainer = [CALayer layer];
UIImage *maskImg = [UIImage imageNamed:#"mask_profile"];
[maskContainer setContents:(id)[maskImg CGImage]];
CGRect frma = maskContainer.frame;
frma.size.width = self.frame.size.width;
frma.size.height = self.frame.size.height;
maskContainer.frame = frma;
[self.imageView.layer setMask:maskContainer];
Its messed up. The overall image starts fading on top.
Can anyone share their insight on the right way to mask?
You could set a drop shadow on your text to make is stand out even over a white background:
myLabel.layer.shadowOpacity = 0.8f;
myLabel.layer.shadowOffset = CGSizeMake(0, 0);
Easiest option is to adjust the alpha on the UILabel to the desired darkness in order to make the text stand out. If you do not want to hide the image and the image itself serves as a dark background, then set the alpha on the label to 0.
The best way to do this is to place the label in a uiview then create a gradient to apply as the background to the uiview. You can create the gradient as either an image with transparency or you can draw it in code. This will create a darkening effect on you bright image just behind the label so the text will pop.

About UIImageView with round corners

I'm trying to make a UIImageView with round corners, so I used [imageView.layer setCornerRadius:5.0f]; it works but not perfectly.
If you look closely, you can see the corners of the image(I uploaded a photo, I don't know if you can see it clearly, there are blue parts in the corners). How should I remove these? thank you.
(P.S.: I also set the border of the view, is that the reason why?)
UIImageView doesn't clip to bounds by default. So while the corner radius is applied its still drawing outside of its designated area.
objc:
[imageView setClipsToBounds:YES];
swift:
imageView.clipsToBounds = true

iOS animate a blur for a view

I would like to quickly animate a blur on a UIView to use as a transition in my app. I'm having trouble knowing where to start. I believe core image is the proper tool for the job. Can anyone point me to a sample of how to blur a UIView? I'm assuming I will need to convert the view into a single UIImage, but I don't know where to proceed from there.
Thanks in advance!
Taking a snapshot of the View and using GPUImage from Brad Larson (the GPUImageGaussianBlurFilter) got me some nice results.
To animate the view I created a ImageView with the blurred image and animated the alpha channel from 0 to 1 to make the blur appear progressively.
Alternatively, I presume its possible to increase the blursize per frame.
#import "GPUImage.h"
...
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
...
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
...
GPUImageGaussianBlurFilter * filter = [[GPUImageGaussianBlurFilter alloc] init];
filter.blurSize = 0.5;
UIImage * blurred = [filter imageByFilteringImage:image];
rasterizeScale of a uiview's layer is what you need, Here is the code for adding blur effect to UIVIew:
CALayer *layer = [self.blurView layer];
[layer setRasterizationScale:0.3];
[layer setShouldRasterize:YES];
For details refer to Apple Documentation of CALayer, Also this tutorial might help You, hope that helps
I recently did some tests with blurring a series of images at different blur settings and animating them simply with UIImageView. You might want to take a look:
AnimatedGaussianBlur

How to mask UIViews in iOS

I've seen similar questions, but haven't found workable answers.
I want to mask a UIView using a grey image (need to convert to alpha scale for masking). The UIView has background. It should be easy to mask an image, but I want to mask any UIView.
Any clues will be appreciated.
I've been working on this problem for a couple of hours and have a solution that I think will do what you want. First, create your masking image using whatever means you see fit. Note that we only need the alpha values here, all other colours will be ignored, so make certain that the method you use supports alpha values. In this example I'm loading from a .png file, but don't try it with .jpg files as they don't have alpha values.
Next, create a new layer, assign your mask to its contents and set this new layer to your UIView's own layer, like so: you should find that this masks the UIView and all its attached subviews:
UIImage *_maskingImage = [UIImage imageNamed:#"mask"];
CALayer *_maskingLayer = [CALayer layer];
_maskingLayer.frame = theView.bounds;
[_maskingLayer setContents:(id)[_maskingImage CGImage]];
[theView.layer setMask:_maskingLayer];
With this done, you can set the UIView's background colour to whatever you like and the mask will be used to create a coloured filter.
EDIT: As of iOS8 you can now mask a view simply by assigning another view to its maskView property. The general rules stay the same in that the maskView's alpha layer is used to determine the opacity of the view it is applied to.
For apps targeting iOS 8.0+ this worked well (in this case, using a gradient as the mask) It avoids any need to resize or position the mask.
// Add gradient mask to view
func addGradientMask(targetView: UIView)
{
let gradientMask = CAGradientLayer()
gradientMask.frame = targetView.bounds
gradientMask.colors = [UIColor.blackColor().CGColor, UIColor.clearColor().CGColor]
gradientMask.locations = [0.8, 1.0]
let maskView: UIView = UIView()
maskView.layer.addSublayer(gradientMask)
targetView.maskView = maskView
}
In my case, I want to remove the mask once the user starts scrolling. This is done with:
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
exerDetailsTableView.maskView = nil
}
where the view is defined as an #IBOutlet:
#IBOutlet weak var exerDetailsTableView: UITableView!
Result:
I don't know the exact code off the top of my head but the basic idea is to have two UIViews. One UIView would have it's image property set to be the grey scale image and the other UIView would be set as usual the only difference is that you would position the initial UIView directly on top of the UIView containing the "normal" image.
I hope that is enough to push your idea a step further.

Resources