gpt4 book ai didi

ios - UISegmentedControl 保持图像的纵横比

转载 作者:搜寻专家 更新时间:2023-10-31 08:25:30 24 4
gpt4 key购买 nike

我很难让 UISegmentedControl 上的图像保持纵横比而不是向所有方向缩放。这是它的样子: UiSegmentedControl maintain aspect ratio

图像是 100X100(除了即将更换的 nr 6),我希望它们保持纵横比。

我试过:

self.segment.contentMode = .ScaleAspectFit
//and:
self.segment.contentMode = UIViewContentMode.Center

有没有一种方法可以定位段中的 UIImageView.. 这样我就可以设置 contentMode.. 对吗?或者有其他方法吗?

谢谢

最佳答案

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
}
}

关于ios - UISegmentedControl 保持图像的纵横比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38936646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com