我有一个UIImageView
,我不想让图像“触碰”视图的边缘,而是希望在它周围有一些“填充”。但是,我已经尝试了以下操作,但出于某种原因它没有改变:
@IBOutlet weak var pictureOutletOne: UIImageView!
//set the image
pictureOutletOne.image = UIImage(named: itemOne)
//set the padding
pictureOutletOne.layoutMargins = UIEdgeInsetsMake(10, 10, 10, 10);
我也尝试过:
pictureOutletOne.translatesAutoresizingMaskIntoConstraints = false
pictureOutletOne.layoutMargins = UIEdgeInsets(top: 10, left: 100, bottom: 10, right: 0)
我已经阅读了很多关于这个的内容,但这些是我找到的解决方案,但它们并没有起作用。使用Swift 3
。
非常感谢。
layoutMargins
only affect subviews that use them.UIImageView
renders image inside in a non-UIView way so you should follow with the answer below where you wrap it intoUIView
- pronebird