Posts

Showing posts with the label uiimageview

UISegmentedControl maintain aspect ratio on image

Image
UISegmentedControl maintain aspect ratio on image I'm having a hard time making images on a UISegmentedControl keep their aspect ratio and not scale to all sides. Here's what it looks like: The images are 100X100(except nr 6 gonna replace soon) and I want them to maintain the aspect ratio. I have tried: self.segment.contentMode = .ScaleAspectFit //and: self.segment.contentMode = UIViewContentMode.Center Are there a way I can target the UIImageView in the segment..that way I can set the contentMode..right? Or is there another approach? Thanks 3 Answers 3 segmentedControl.subviews.flatMap{$0.subviews}.forEach { subview in if let imageView = subview as? UIImageView, let image = imageView.image, image.size.width > 5 { // The imageView which isn't separator imageView.contentMode = .scaleAspectFit } } Please add an explanation. ...

Swift: change UIImageView image midway during animation

Swift: change UIImageView image midway during animation I have this code to create animation imageView : imageView imageView.layer.anchorPoint = CGPoint(x: 0, y: 0.5) var transform = CATransform3DIdentity transform.m34 = -0.001 imageView.layer.transform = transform UIView.animate(withDuration: 3) { self.imageView.layer.transform = CATransform3DRotate(transform, .pi, 0, 1, 0) self.imageViewCenterConstraintX.constant = 0 self.view.layoutIfNeeded() } In this code imageView rotate with 180 degrees. I want to change image after imageView rotate with 90 degrees. imageView imageView pi/2 u can do in params – Abhishek Thapliyal Jul 1 at 10:46 @AbhishekThapliyal And how do I write this in the code? How to let the device know that the ima...