Drawing a rectangle in UIView

前端 未结 5 606
不思量自难忘°
不思量自难忘° 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

    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
        CGRect rectangle = CGRectMake(0, 100, 320, 100);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.0);   //this is the transparent color
        CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.5);
        CGContextFillRect(context, rectangle);
        CGContextStrokeRect(context, rectangle);    //this will draw the border
    
    }
    

    the effect is like this (backgroundColor is blue)

    enter image description here

提交回复
热议问题