ios - 如何将 UIImageView 放入 CAShapeLayer 中?

标签 ios swift uiimageview cashapelayer

我不确定如何将 UIImageView 放入我正在创建的 Circular CAShapeLayer 中。目前,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
}

最佳答案

找到解决方案:

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

关于ios - 如何将 UIImageView 放入 CAShapeLayer 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35052567/

相关文章:

ios - 调用 API 花费太多时间来获得响应的问题

ios - Xcode 5 与 iOS 7 : 'Story Board: There are unexpected subviews in the container view.' 中的 NSInternalInconsistencyException

ios - setup func 无法更改 viewController 中的背景颜色

ios - 如何使用 mapbox ios 标记执行操作

iphone - 在 iPhone iOS 上堆叠多个具有透明度的图像

ios - 使用 AutoLayout 更改 UIImageView 框架大小

ios - 我们如何在移动设备(iOS 和 Android)上播放 Scorm 内容?

ios - 组件的尾部约束等于其前导约束

ios - iOS Swift 读取 Json 失败

iphone - iOS SDK UIViewContentModeScaleAspectFit 与 UIViewContentModeScaleAspectFill