Draw a simple circle uiimage

Thanks for the Q&A! Swift code as below: extension UIImage { class func circle(diameter: CGFloat, color: UIColor) -> UIImage { UIGraphicsBeginImageContextWithOptions(CGSizeMake(diameter, diameter), false, 0) let ctx = UIGraphicsGetCurrentContext() CGContextSaveGState(ctx) let rect = CGRectMake(0, 0, diameter, diameter) CGContextSetFillColorWithColor(ctx, color.CGColor) CGContextFillEllipseInRect(ctx, rect) CGContextRestoreGState(ctx) let img = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return img } } Swift 3 version provided by … Read more

Cut a UIImage into a circle

Xcode 11 • Swift 5.1 or later edit/update: For iOS10+ We can use UIGraphicsImageRenderer. For older Swift syntax check edit history. extension UIImage { var isPortrait: Bool { size.height > size.width } var isLandscape: Bool { size.width > size.height } var breadth: CGFloat { min(size.width, size.height) } var breadthSize: CGSize { .init(width: breadth, height: breadth) … Read more

How to add image in UINavigationBar in IPhone app

One way to do this is to use UINavigationItem.titleView and UINavigationItem.rightBarButtonItem. Like this : viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”yourimage.png”]]; UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@”yourimage2.jpg”]]]; viewController.navigationItem.rightBarButtonItem = item; Here I am using UIImageView as custom view, but it can be UIButton with custom image.

Defining the file a UIImage will use (Swift)

Even though you are using Swift, all the classes that come from UIKit and other libraries still are written in Objective-C. There is no difference in the interfaces to these libraries, just the syntax. In this case, you need to use the object construction syntax: var image = UIImage(named:”ImageName”)

UIImage from CALayer in iOS

Sounds like you want to render your layer into a UIImage. In that case, the method below should do the trick. Just add this to your view or controller class, or create a category on CALayer. Obj-C – (UIImage *)imageFromLayer:(CALayer *)layer { UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, 0); [layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return outputImage; } … Read more

Storing images locally on an iOS device

The simplest way is to save it in the app’s Documents directory and save the path with NSUserDefaults like so: NSData *imageData = UIImagePNGRepresentation(newImage); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *imagePath =[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@”%@.png”,@”cached”]]; NSLog(@”pre writing to file”); if (![imageData writeToFile:imagePath atomically:NO]) { NSLog(@”Failed to cache image data to … Read more

How can I change image tintColor

Try to generate new image for yourself UIImage *newImage = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; UIGraphicsBeginImageContextWithOptions(image.size, NO, newImage.scale); [yourTintColor set]; [newImage drawInRect:CGRectMake(0, 0, image.size.width, newImage.size.height)]; newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); _sketchImageView.image = newImage; And use it. Good luck ======= UPDATE ======= This solution will only change color of all pixel’s image. Example: we have a book image: http://pngimg.com/upload/book_PNG2113.png And … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)