Position a subview on the edge of a circular shaped view

后端 未结 2 1018
有刺的猬
有刺的猬 2020-12-10 23:06

I\'m trying to create a profile picture view that looks like the mock-up below. It has a small green dot to denote the user\'s online status.

I\'m creating

2条回答
  •  悲哀的现实
    2020-12-10 23:18

    Change your initialize function with the following: You can see the result in the given image link...

      private func initialize() {
        backgroundColor = .clear
    
        imageView = UIImageView(frame: bounds)
        imageView.backgroundColor = .lightGray
        imageView.clipsToBounds = true
        imageView.layer.cornerRadius = imageView.frame.height / 2
        addSubview(imageView)
    
        onlineStatusView = UIView(frame: CGRect(x: 0, y: 0, width: (bounds.height / 5), height: (bounds.height / 5)))
        onlineStatusView.center = CGPoint(x: bounds.width / 7, y: bounds.height / 7)
        onlineStatusView.backgroundColor = .white
        onlineStatusView.clipsToBounds = true
        onlineStatusView.layer.cornerRadius = onlineStatusView.frame.height / 2
        addSubview(onlineStatusView)
    
        onlineStatusDotView = UIView(frame: CGRect(x: 0, y: 0, width: (onlineStatusView.bounds.height / 1.3), height: (onlineStatusView.bounds.height / 1.3)))
          onlineStatusDotView.center = CGPoint(x: onlineStatusView.frame.width / 2, y: onlineStatusView.frame.height / 2)
        onlineStatusDotView.backgroundColor = UIColor(red: 0.17, green: 0.71, blue: 0.45, alpha: 1.0)
        onlineStatusDotView.clipsToBounds = true
        onlineStatusDotView.layer.cornerRadius = onlineStatusDotView.frame.height / 2
        onlineStatusView.addSubview(onlineStatusDotView)
    }
    

提交回复
热议问题