Remove Auto-Layout Constraints for Specific Object
I agree Xcode auto-layout is horrible to use if you want something particular… What I use to remove constraints programatically: [detailsPhotoView removeConstraints:detailsPhotoView.constraints];
I agree Xcode auto-layout is horrible to use if you want something particular… What I use to remove constraints programatically: [detailsPhotoView removeConstraints:detailsPhotoView.constraints];
You don’t have to encode it. Simply make a NSUrl, it knows the “data:”-url. NSURL *url = [NSURL URLWithString:base64String]; NSData *imageData = [NSData dataWithContentsOfURL:url]; UIImage *ret = [UIImage imageWithData:imageData]; As mentioned in the comments, you have to make sure that you prepend your data with data:image/png;base64, or else your base64 data is useless.
Objective-C: -(CGRect)frameForImage:(UIImage*)image inImageViewAspectFit:(UIImageView*)imageView { float imageRatio = image.size.width / image.size.height; float viewRatio = imageView.frame.size.width / imageView.frame.size.height; if(imageRatio < viewRatio) { float scale = imageView.frame.size.height / image.size.height; float width = scale * image.size.width; float topLeftX = (imageView.frame.size.width – width) * 0.5; return CGRectMake(topLeftX, 0, width, imageView.frame.size.height); } else { float scale = imageView.frame.size.width / image.size.width; float … Read more
No. But you can easily add an image view as the accessory view to a table cell for the same effect. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”foo.png”]]; cell.accessoryView = imageView; [imageView release];
This is a general answer for the sake of future viewers. It is based on the question title rather than the details of the original question. How to add a UIImage to a CALayer You can add an image to a view’s layer simply by using its contents property: myView.layer.contents = UIImage(named: “star”)?.cgImage Note that … Read more
Just use the size property of UIImage, for example: NSURL *url = [NSURL URLWithString:path]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *img = [[UIImage alloc] initWithData:data]; CGSize size = img.size;
You cannot add a subview to UIImageView in interface builder for reasons only known to Apple! You are right in saying that you can addSubview programmatically, but then, the overhead of setting autoresizing masks and placements of subviews should all be handled in code, which is cumbersome. So there is an easy workaround. Instead of … Read more
In short, you cannot do this with a UIImageView. One solution is to subclass a UIView containing an UIImageView and change its frame according to image size. For example, you can find one version here.
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
Easy fix solution: Just add a new runtime attribute which will set the tintColor of the UIImageView to the specified color and ensure the image is tinted. You will still need to set your image to be rendered as a template image in your Images.xcassets file. This way you dont need any additional outlets, extensions … Read more