0
林與出Interface Builder的一個項目工作的基本問題,約CoreGraphics在
我想畫一條線,測試方,但不工作 這裏的代碼
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClearRect(context, rect); //Set the stroke (pen) color CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); //Set the width of the pen mark CGContextSetLineWidth(context, 5.0); //Start at this point //CGContextMoveToPoint(context, 10.0, 30.0); CGContextMoveToPoint(context, 20, 20); //Give instructions to the CGContext //(move "pen" around the screen) CGContextAddLineToPoint(context, 310.0, 30.0); CGContextStrokePath(context); // Draw a red solid square CGContextSetRGBFillColor(context, 255, 0, 0, 1); CGContextFillRect(context, CGRectMake(10, 10, 50, 50)); } - (void)viewDidLoad { [super viewDidLoad]; self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; self.view.backgroundColor = [UIColor grayColor]; UILabel *labelA = [[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 20)]autorelease]; labelA.text = @"mk ss9"; [self.view addSubview:labelA]; }
標籤顯示正常,但線條和方形不顯示,缺少什麼?
非常感謝!