Tutorial by Examples

With local image Swift let image = UIImage(named: "imageFromBundleOrAsset") Objective-C UIImage *image = [UIImage imageNamed:@"imageFromBundleOrAsset"]; Note The method imageNamed caches the image's contents to memory. Loading many large images that way can cause low...
Creating and returning an image object by loading the image data from the file at the specified path. Example: UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[cellCountry objectForKey:@"Country_Flag"] ofType:nil]]; Using Array: Example NSM...
In the example of a message bubble illustrated below: the corners of the image should remain unchanged which is specified by UIEdgeInsets, but the borders and center of the image should expand to cover the new size. let insets = UIEdgeInsetsMake(12.0, 20.0, 22.0, 12.0) let image = UIImage(na...
The isEqual: method is the only reliable way to determine whether two images contain the same image data. The image objects you create may be different from each other, even when you initialize them with the same cached image data. The only way to determine their equality is to use the isEqual...
Swift let color = UIColor.redColor() let size = CGSize(width: 200, height: 200) UIGraphicsBeginImageContextWithOptions(size, false, 0.0) CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), color.CGColor) CGContextFillRect(UIGraphicsGetCurrentContext(), CGRect(origin: .zero, size: si...
Creating Gradient UIImage with colors in CGRect Swift: extension UIImage { static func gradientImageWithBounds(bounds: CGRect, colors: [CGColor]) -> UIImage { let gradientLayer = CAGradientLayer() gradientLayer.frame = bounds gradientLayer.colors = colors ...
+ (CALayer *)gradientBGLayerForBounds:(CGRect)bounds colors:(NSArray *)colors { CAGradientLayer * gradientBG = [CAGradientLayer layer]; gradientBG.frame = bounds; gradientBG.colors = colors; return gradientBG; }
Encoding //convert the image to NSData first let imageData:NSData = UIImagePNGRepresentation(image)! // convert the NSData to base64 encoding let strBase64:String = imageData.base64EncodedStringWithOptions(.Encoding64CharacterLineLength) Decoding let dataDecoded:NSData = NSData(base64Encoded...
//Here self.webView is the view whose screenshot I need to take //The screenshot is saved in jpg format in the application directory to avoid any loss of quality in retina display devices i.e. all current devices running iOS 10 UIGraphicsBeginImageContextWithOptions(self.webView.bounds.size, N...
Use same UIImage with multiple theme base app by just applying UIColor to UIImage instance as following. // *** Create an UIImage instance with RenderingMode AlwaysTemplate *** UIImage *imgMenu = [[UIImage imageNamed:@"iconMenu"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]...
Swift Add this extension to UIImage : extension UIImage { func maskWithColor(color: UIColor) -> UIImage? { let maskImage = self.CGImage let width = self.size.width let height = self.size.height let bounds = CGRectMake(0, 0, width, height) ...

Page 1 of 1