How do you create a UIImage View Programmatically – Swift

First you create a UIImage from your image file, then create a UIImageView from that: let imageName = “yourImage.png” let image = UIImage(named: imageName) let imageView = UIImageView(image: image!) Finally you’ll need to give imageView a frame and add it your view for it to be visible: imageView.frame = CGRect(x: 0, y: 0, width: 100, … Read more

Create UIImage with solid color in Swift

Another nice solution, Swift 3.0 public extension UIImage { convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) { let rect = CGRect(origin: .zero, size: size) UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0) color.setFill() UIRectFill(rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() guard let cgImage = image?.cgImage else { return nil } self.init(cgImage: cgImage) } } Swift 2.2 compatible, is … Read more

Creating a UIImage from a UIColor to use as a background image for UIButton [duplicate]

I created a category around UIButton to be able to set the background color of the button and set the state. You might find this useful. @implementation UIButton (ButtonMagic) – (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state { [self setBackgroundImage:[UIButton imageFromColor:backgroundColor] forState:state]; } + (UIImage *)imageFromColor:(UIColor *)color { CGRect rect = CGRectMake(0, 0, 1, 1); UIGraphicsBeginImageContext(rect.size); CGContextRef context = … Read more

How to Rotate a UIImage 90 degrees?

I believe the easiest way (and thread safe too) is to do: //assume that the image is loaded in landscape mode from disk UIImage * landscapeImage = [UIImage imageNamed:imgname]; UIImage * portraitImage = [[UIImage alloc] initWithCGImage: landscapeImage.CGImage scale: 1.0 orientation: UIImageOrientationRight]; Note: As Brainware said this only modifies the orientation data of the image – … Read more

UIImageView aspect fit and center

Just pasting the solution: Just like @manohar said imageView.contentMode = UIViewContentModeCenter; if (imageView.bounds.size.width > ((UIImage*)imagesArray[i]).size.width && imageView.bounds.size.height > ((UIImage*)imagesArray[i]).size.height) { imageView.contentMode = UIViewContentModeScaleAspectFit; } solved my problem

How do I export UIImage array as a movie?

Take a look at AVAssetWriter and the rest of the AVFoundation framework. The writer has an input of type AVAssetWriterInput, which in turn has a method called appendSampleBuffer: that lets you add individual frames to a video stream. Essentially you’ll have to: 1) Wire the writer: NSError *error = nil; AVAssetWriter *videoWriter = [[AVAssetWriter alloc] … Read more

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