【发布时间】:2017-02-15 07:38:38
【问题描述】:
我正在尝试使用设置背景颜色和不透明度的视图在图像顶部创建蒙版,它似乎在 iPhone 7 中运行良好。当我在 iPhone 中运行应用程序时出现问题7 plus 模拟器,由于某种原因,面具保持 iPhone 7 尺寸的大小。
我创建了一个自定义 UIImageView 类:
class LoginBackgroundImageView: UIImageView {
override func awakeFromNib() {
super.awakeFromNib()
// Set a mask on image background
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor(white: 0, alpha: 0.4)
bgColorView.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
addSubview(bgColorView)
}
}
【问题讨论】:
-
bgColorView.frame = CGRect(x: 0, y: 0, width: yourimage.frame.width, height: yourimage.frame.height) 不知道这个框架来自哪里?我假设您在框架中设置硬编码值。
-
或者添加self.frame
-
试试这个
bgColorView.frame = frame -
你试过设置约束吗??