【问题标题】:How to draw a border around two overlapping UIViews如何在两个重叠的 UIView 周围绘制边框
【发布时间】:2017-09-28 22:08:23
【问题描述】:

我有两个 UIView 在重叠时会创建一个独特的形状,我想在组合视图周围绘制一个边框。

这样做的正确方法是什么?

UIView 是:

  1. 用于显示用户个人资料图像的圆形图像视图
  2. 将包含用户配置文件数据(即姓名、出生日期等)的矩形视图

这是两个视图组合在一起的图像:

【问题讨论】:

    标签: uiview border shape mask


    【解决方案1】:

    好的,通过以下操作弄清楚了:

    1. 在矩形 UIView 上设置边框
    2. UIBezierPath创建一个CAShapeLayer来绘制一个半圆,并在drawRect方法中将它添加到圆UIView's图层中:

      覆盖 func draw(_ rect: CGRect) { super.draw(矩形)

      let shapeLayer = CAShapeLayer()
      let topSemiCirclePath = UIBezierPath(arcCenter: userImageView.center, radius: userImageView.bounds.size.width / 2.0, startAngle: CGFloat(Double.pi), endAngle: CGFloat(Double.pi / 180), clockwise: true)
      topSemiCirclePath.lineWidth = 2.0
      UIColor.lightGray.setStroke()
      topSemiCirclePath.stroke()
      shapeLayer.path = topSemiCirclePath.cgPath
      userImageView.layer.addSublayer(shapeLayer)
      

      }

    【讨论】:

      猜你喜欢
      • 2020-10-15
      • 1970-01-01
      • 2018-07-05
      • 2011-01-19
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多