0

iOS で uiimageview を描画したい.画面全体に描画することはできますが、特定の領域のみに描画したい.私のコードは:-

    UITouch *touch = [touches anyObject];    
    currentPoint = [touch locationInView:self.view]; //// tracing whatever ur finger touching the screen
    NSLog(@"%data",currentPoint);
    UIGraphicsBeginImageContext(CGSizeMake  (300,568)) ;  /// (300,568));   //// 320, 568, 480 iph4 screen ,568 ip5 screen
    [drawImage.image drawInRect:CGRectMake(0,0, 300,568)];    //(0,0, 300,568)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext (), kCGLineCapRound); // round line
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 18.0);  //// LINE WIDTH DIAMETER THE STROKE
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 1, 1, 1);  ///// RGB COLOUR
    CGContextBeginPath(UIGraphicsGetCurrentContext());   ///// START WHEN WE DRAW THE PATH.
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);  /////
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());

   // CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
  [drawImage setFrame:CGRectMake (0,0, 300, 568)]; //// (0, 0, 300,568)]; ///(100, 100, 150,280)];
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); ///// WHOLE UPPER PARA defined
UIGraphicsEndImageContext(); //// DONE DRAWING
lastPoint = currentPoint;  ////
4

1 に答える 1

0

UIView のサブクラスを作成してオーバーライドするdrawRect

- (void)drawRect:(CGRect)rect
{
    // do your drawing here
}

ビューをサブビューとして UIImageView に追加します

MyCustomView *customView = [[MyCustomView alloc] initWithFrame:self.imageView.bounds];
[self.imageView addSubview:customView];

図面をカスタマイズするパラメータでビューを更新します。

于 2013-07-25T14:43:40.847 に答える