How to set imageView in circle like imageContacts in Swift correctly?

This is solution which I have used in my app: var image: UIImage = UIImage(named: “imageName”) imageView.layer.borderWidth = 1.0 imageView.layer.masksToBounds = false imageView.layer.borderColor = UIColor.whiteColor().CGColor imageView.layer.cornerRadius = image.frame.size.width/2 imageView.clipsToBounds = true Swift 4.0 let image = UIImage(named: “imageName”) imageView.layer.borderWidth = 1.0 imageView.layer.masksToBounds = false imageView.layer.borderColor = UIColor.white.cgColor imageView.layer.cornerRadius = image.frame.size.width / 2 imageView.clipsToBounds = true

(iphone) UIImageView setImage: leaks?

Yes, UIImageView setImage does leak! Actually, leaks CGImage, not UIImage (as instrument “allocation” shows) I use BrutalUIImage instead of UIImage @interface BrutalUIImageView : UIView { UIImage *image; } @property(nonatomic, retain) UIImage *image; @end @implementation BrutalUIImageView @synthesize image; – (void)setImage:(UIImage *)anImage { [image autorelease]; image = [anImage retain]; [self setNeedsDisplay]; } – (void)drawRect:(CGRect)rect { [super drawRect:rect]; … Read more

Replace a particular color inside an image with another color

You have to iterate through each pixel in the image and take its rgb values Check its rgb values matches your fromColor rgb values, if yes change the pixel value to your toColor rgb values.If not, just leave that pixel and go to next one.. Wrote a function from memory..errors possible..correct yourself -(UIImage*)changeColor:(UIImage*)myImage fromColor:(UIColor*)fromColor toColor:(UIColor*)toColor{ … Read more

How to get the displayed image frame from UIImageView?

If it’s UIViewContentModeScaleAspectFit, it’s something like this: UIImageView *iv; // your image view CGSize imageSize = iv.image.size; CGFloat imageScale = fminf(CGRectGetWidth(iv.bounds)/imageSize.width, CGRectGetHeight(iv.bounds)/imageSize.height); CGSize scaledImageSize = CGSizeMake(imageSize.width*imageScale, imageSize.height*imageScale); CGRect imageFrame = CGRectMake(roundf(0.5f*(CGRectGetWidth(iv.bounds)-scaledImageSize.width)), roundf(0.5f*(CGRectGetHeight(iv.bounds)-scaledImageSize.height)), roundf(scaledImageSize.width), roundf(scaledImageSize.height));