UISegmentedControl maintain aspect ratio on 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. ...