How would I tint an image programmatically on iOS?

In iOS7, they’ve introduced tintColor property on UIImageView and renderingMode on UIImage. To tint an UIImage on iOS7, all you have to do is: UIImageView* imageView = … UIImage* originalImage = … UIImage* imageForRendering = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageView.image = imageForRendering; imageView.tintColor = [UIColor redColor]; // or any color you want to tint it with

How to set the opacity/alpha of a UIImage?

I just needed to do this, but thought Steven’s solution would be slow. This should hopefully use graphics HW. Create a category on UIImage: – (UIImage *)imageByApplyingAlpha:(CGFloat) alpha { UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGRect area = CGRectMake(0, 0, self.size.width, self.size.height); CGContextScaleCTM(ctx, 1, -1); CGContextTranslateCTM(ctx, 0, -area.size.height); CGContextSetBlendMode(ctx, kCGBlendModeMultiply); CGContextSetAlpha(ctx, alpha); CGContextDrawImage(ctx, area, … Read more

Resize UIImage to 200x200pt/px

Here is my code. The Image is in width 850 px and not 200 px: func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage { let scale = newWidth / image.size.width let newHeight = image.size.height * scale UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight)) image.drawInRect(CGRectMake(0, 0, newWidth, newHeight)) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage } @IBAction func chooseImage(sender: AnyObject) { var … Read more

Tricks for improving iPhone UITableView scrolling performance?

Cache the height of the rows (the table view can request this frequently) Create a least-recently-used cache for the images used in the table (and invalidate all the inactive entries when you receive a memory warning) Draw everything in the UITableViewCell‘s drawRect: if possible avoid subviews at all costs (or if you require the standard … Read more

How to Convert UIView to PDF within iOS?

Note that the following method creates just a bitmap of the view; it does not create actual typography. (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename { // Creates a mutable data object for updating with binary data, like a byte array NSMutableData *pdfData = [NSMutableData data]; // Points the pdf converter to the mutable data object and to the UIView … Read more

How do I resize the UIImage to reduce upload image size

Xcode 9 • Swift 4 or later edit/update: For iOS10+ We can use UIGraphicsImageRenderer. For older Swift syntax check edit history. extension UIImage { func resized(withPercentage percentage: CGFloat, isOpaque: Bool = true) -> UIImage? { let canvas = CGSize(width: size.width * percentage, height: size.height * percentage) let format = imageRendererFormat format.opaque = isOpaque return UIGraphicsImageRenderer(size: … Read more

How do I add text to an image in iOS Swift?

I figured it out: func textToImage(drawText: NSString, inImage: UIImage, atPoint: CGPoint) -> UIImage{ // Setup the font specific variables var textColor = UIColor.whiteColor() var textFont = UIFont(name: “Helvetica Bold”, size: 12)! // Setup the image context using the passed image let scale = UIScreen.mainScreen().scale UIGraphicsBeginImageContextWithOptions(inImage.size, false, scale) // Setup the font attributes that will be … Read more

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