我正在UIImageView中使用SF符号图像.我也给出了约束.我看到在不同的模拟器中运行相同的代码实际上增加了映像的宽度,但我想给不同的iOS模拟器提供固定的宽度.
以下是该图像的代码:
let rightImageView: UIImageView = {
let rightImageView = UIImageView()
rightImageView.image = UIImage(systemName: "arrow.right")
rightImageView.translatesAutoresizingMaskIntoConstraints = false
rightImageView.tintColor = .purple
return rightImageView
}()
下面是对它和其他属性的约束:
private func setUpUI() {
view.addSubview(stackview)
stackview.dm_addArrangedSubviews(titleLable)
stackview.dm_addArrangedSubviews(viewAllLable)
stackview.dm_addArrangedSubviews(rightImageView)
view.addSubview(collectionView)
let safeArea = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
stackview.leadingAnchor.constraint(equalTo: view.leadingAnchor),
stackview.trailingAnchor.constraint(equalTo: view.trailingAnchor),
stackview.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.topAnchor.constraint(equalTo: stackview.bottomAnchor),
collectionView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor),
collectionView.heightAnchor.constraint(equalToConstant: view.frame.width/2)
])
}
Here is the screenshot in iPhone 15 Pro Max:
Here is the screenshot in iPhone 15 simulator:
Here is the screenshot on different mode, the right arrow image width is set properly:
如您所见,rightImageView
属性的宽度增加了.我如何为不同的设备提供固定的宽度?