如何在CAShapeLayer中安装UIImageView?

时间:2016-01-28 03:54:17

标签: ios swift uiimageview cashapelayer

我不确定如何在我正在创建的循环CAShapeLayer中使用UIImageView。目前,UIImageView(imageViewObject)太大了,掩盖了我制作的另外两个UILabel。有什么提示吗?

let imageViewObject = UIImageView(frame:CGRectMake(0, 0, 100, 100))
let statusLabel = UILabel(frame: CGRectMake(0, 0, 200, 20))
let percentageLabel = UILabel(frame: CGRectMake(0, 0, 200, 20))

override func layoutSubviews() {
    super.layoutSubviews()
    circlePathLayer.frame = bounds
    circlePathLayer.path = circlePath().CGPath

    statusLabel.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
    percentageLabel.center = CGPointMake(CGRectGetMidX(self.bounds), 4 * frame.height / 5)
    imageViewObject.center = CGPointMake(CGRectGetMidX(self.bounds), 1 * frame.height / 5)  //This doesn't fit this inside
}

1 个答案:

答案 0 :(得分:1)

找到解决方案:

let imageViewObject = UIImageView(frame:CGRectMake(0, 0, 100, 100))
let statusLabel = UILabel(frame: CGRectMake(0, 0, 200, 20))
let percentageLabel = UILabel(frame: CGRectMake(0, 0, 200, 20))

override func layoutSubviews() {
    super.layoutSubviews()
    circlePathLayer.frame = bounds
    circlePathLayer.path = circlePath().CGPath

    statusLabel.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
    percentageLabel.center = CGPointMake(CGRectGetMidX(self.bounds), 4 * frame.height / 5)
    imageViewObject.frame = CGRectMake(2 * frame.width / 5, 1 * frame.height / 5, 20, 20);
}