How to merge two UIImages?

Hope this may help you, var bottomImage = UIImage(named: “bottom.png”) var topImage = UIImage(named: “top.png”) var size = CGSize(width: 300, height: 300) UIGraphicsBeginImageContext(size) let areaSize = CGRect(x: 0, y: 0, width: size.width, height: size.height) bottomImage!.draw(in: areaSize) topImage!.draw(in: areaSize, blendMode: .normal, alpha: 0.8) var newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() All the Best 🙂

Can’t add a corner radius and a shadow

Yes, yes there is… If you want both a corner radius and a drop shadow, you don’t turn on -masksToBounds, but rather set the corner radius and set the bezier path of the shadow with a rounded rect. Keep the radius of the two the same: [layer setShadowOffset:CGSizeMake(0, 3)]; [layer setShadowOpacity:0.4]; [layer setShadowRadius:3.0f]; [layer setShouldRasterize:YES]; … Read more

Round top corners of a UIView and add border

The mask layer doesn’t get drawn, just used to compute the mask. Try: -(void)roundCorners:(UIRectCorner)corners radius:(CGFloat)radius { CGRect bounds = self.bounds; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = bounds; maskLayer.path = maskPath.CGPath; self.layer.mask = maskLayer; CAShapeLayer* frameLayer = [CAShapeLayer layer]; frameLayer.frame = bounds; frameLayer.path = maskPath.CGPath; frameLayer.strokeColor = … Read more

NSImage size not real size with some pictures?

NSImage size method returns size information that is screen resolution dependent. To get the size represented in the actual file image you need to use an NSImageRep. You can get an NSImageRep from an NSImage using the representations method. Alternatively you can create a NSBitmapImageRep subclass instance directly like this: NSArray * imageReps = [NSBitmapImageRep … Read more

Applying a Gradient to CAShapeLayer

You could use the path of your shape to create a masking layer and apply that on the gradient layer, like this: UIView *v = [[UIView alloc] initWithFrame:self.window.frame]; CAShapeLayer *gradientMask = [CAShapeLayer layer]; gradientMask.fillColor = [[UIColor clearColor] CGColor]; gradientMask.strokeColor = [[UIColor blackColor] CGColor]; gradientMask.lineWidth = 4; gradientMask.frame = CGRectMake(0, 0, v.bounds.size.width, v.bounds.size.height); CGMutablePathRef t = … Read more