简体   繁体   English

如何在CAShapeLayer中安装UIImageView?

[英]How to fit a UIImageView inside a CAShapeLayer?

I am not sure how to fit the UIImageView in a Circular CAShapeLayer that I am creating. 我不确定如何在我创建的圆形CAShapeLayer中适合UIImageView。 Currently, the UIImageView (imageViewObject) is way too large and is covering up the other two UILabels I have made. 目前,UIImageView(imageViewObject)太大了,并且掩盖了我制作的其他两个UILabel。 Any tips? 有小费吗?

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
}

Found a solution: 找到一个解决方案:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM