Drawing a rectangle in UIView

前端 未结 5 572
不思量自难忘°
不思量自难忘° 2020-12-29 08:55

I am trying to draw a transparent rectangle in my UIView which has a black border.

My code however creates a completely black rectangle. Here\'s my code so far:

5条回答
  •  被撕碎了的回忆
    2020-12-29 09:12

    One handy tip ......

    Very often, when you need to draw a square

    it's easier to just draw a 'thick stripe' .....

        let context = UIGraphicsGetCurrentContext()
        context!.setLineWidth(100)
        context!.setStrokeColor(blah.cgColor)
        context?.move(to: CGPoint(x: 500, y: 200))
        context?.addLine(to: CGPoint(x: 500, y: 300))
        context!.strokePath()
    

    That will draw a square, which runs downwards from 200 to 300.

    It's centered on 500 across, and is 100 wide.

提交回复
热议问题