【发布时间】:2019-04-30 08:08:20
【问题描述】:
我是 iOS 开发的新手。如果使用故事板,我可以像这样在视图控制器中放置一个图像视图
我需要以编程方式制作类似的东西。
所以我有一个名为 RevealingSplashView 的库中的自定义视图,但我需要向该自定义 UI 视图添加一个图像视图。我只知道添加图像视图,可能是这样的
let imageName = "yourImage.png"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 200)
revealingSplashView.addSubview(imageView)
但我不知道如何将该约束设置为图像视图
一个。对齐到中心 x 到 superview
b.与 superview 0.8 的比例宽度
c。高度限制 = 25
d。将底部对齐到安全区域 = 32
怎么做?
这是我之前想要添加图像视图的代码
let screenSize = UIScreen.main.bounds
let iconWidth = (screenSize.width) * 0.8
let iconHeight = iconWidth * 1 // ratio 1:1
revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "Loading Page Asset")!,iconInitialSize: CGSize(width: iconWidth, height: iconHeight), backgroundColor: AppColor.mainYellow.getUIColor())
revealingSplashView.animationType = SplashAnimationType.twitter
revealingSplashView.imageView?.contentMode = .scaleAspectFill
// add loading indicator to RevealingSplashView Programatically
revealingSplashViewIndicator.color = UIColor.white
revealingSplashViewIndicator.frame = CGRect(x: 0.0, y: 0.0, width: 30.0, height: 30.0)
revealingSplashViewIndicator.center = CGPoint(x: self.view.center.x, y: self.view.center.y + (iconHeight/2) + 64 )
revealingSplashView.addSubview(revealingSplashViewIndicator)
revealingSplashViewIndicator.bringSubviewToFront(self.revealingSplashView)
revealingSplashViewIndicator.startAnimating()
let window = UIApplication.shared.keyWindow
window?.addSubview(revealingSplashView)
【问题讨论】:
标签: ios swift autolayout