2011-06-21 18 views
2

到目前爲止,我有一個繪圖。我有不同的顏色按鈕,但我不知道如何改變它們的顏色。我把所有的RGB顏色代碼,但我怎麼用IBAction爲使它所以,它改變了CGContextSetRGBStrokeColorUIGraphicsGetCurrentContext()CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext)

.H:

@interface GameScreen : UIViewController { 

    BOOL mouseSwiped; 
    float lineWidth; 
    CGPoint lastPoint; 
    IBOutlet UIImageView *drawImage; 
} 
@end 

.M:

#import "GameScreen.h" 
#import "DoodlePicViewController.h" 
#import "Settings.h" 

@implementation GameScreen 

@synthesize theimageView,choosePhoto, takePhoto; 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    mouseSwiped = NO; 
    UITouch *touch = [touches anyObject]; 
    lineWidth = thickness.value; 

    lastPoint = [touch locationInView:self.view]; 
    lastPoint.y -= 20; 

} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    mouseSwiped = YES; 

    UITouch *touch = [touches anyObject]; 
    CGPoint currentPoint = [touch locationInView:self.view]; 
    currentPoint.y -= 20; 


    UIGraphicsBeginImageContext(self.view.frame.size); 
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth); 
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1.0, 1.0, 1.0, 1.0); 
    CGContextBeginPath(UIGraphicsGetCurrentContext()); 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    lastPoint = currentPoint; 



} 



- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [touches anyObject]; 


    if(!mouseSwiped) { 
     UIGraphicsBeginImageContext(self.view.frame.size); 
     [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth); 
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); 
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextStrokePath(UIGraphicsGetCurrentContext()); 
     CGContextFlush(UIGraphicsGetCurrentContext()); 
     drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
    } 
} 


@end 

我真的想搞清楚,但我卡住了☹

+0

所以你的繪圖工作,但你想根據用戶輸入,這可能是基於幾個按鈕右? –

回答

1

I thi你可以使用一個滑塊作爲它的值從0到1.你可以得到3個滑塊的值,然後將它們傳遞給CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1.0,1.0,1.0,1.0),沒有IB也可以做到這一點。我不認爲IB是一件好事。

相關問題