How to draw a rectangle?
问题 I want to draw a filled rectangle in my viewContoller's view. I wrote the code below in viewDidLoad. But there is no change. What is wrong? CGRect rectangle = CGRectMake(0, 100, 320, 100); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0); CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); CGContextFillRect(context, rectangle); 回答1: You can't do it in a viewController. You need to extend your View and add the code under "drawRect