IOS绘图应用程序,更改按钮颜色

时间:2014-12-17 15:50:32

标签: ios

我做了一个简单的绘图应用程序,带有一个工具面板,其中包含一支铅笔,一支画笔和一块橡皮擦。有12种不同颜色可供选择。

现在,我想要铅笔和画笔图像,从颜色面板改变活动颜色的颜色。我该怎么做?

喜欢的东西;

当按下工具按钮:铅笔时,彩色铅笔(图像)是颜色:变色。

如何在代码中翻译?

这是我的按钮代码。

- (IBAction)colorChange:(id)sender
{

  UIButton *PressedButton = (UIButton*)sender;


switch (PressedButton.tag) {
    case 0:
        self.drawingView.lineColor = RGB(32, 152, 188);

        break;

    case 1:
        self.drawingView.lineColor = RGB(33, 114, 177);

        break;

    case 2:
        self.drawingView.lineColor = RGB(65, 79, 155);

        break;

    case 3:
        self.drawingView.lineColor = RGB(110, 58, 141);

        break;

    case 4:
        self.drawingView.lineColor = RGB(195, 26, 126);
                   break;

    case 5:
        self.drawingView.lineColor = RGB(228, 36, 40);

        break;

    case 6:
        self.drawingView.lineColor = RGB(234, 98, 36);

        break;

    case 7:
        self.drawingView.lineColor = RGB(241, 141, 33);

        break;

    case 8:
        self.drawingView.lineColor = RGB(252, 199, 19);

        break;

    case 9:
        self.drawingView.lineColor = RGB(255, 240, 79);

        break;

    case 10:
        self.drawingView.lineColor = RGB(139, 188, 63);
                   break;

    case 11:
        self.drawingView.lineColor = RGB(0, 144, 92);

        break;

  }

}

- (IBAction)toolChange:(id)sender
{
UIButton *toolButton = (UIButton*)sender;


switch (toolButton.tag){
    case 0:
        self.drawingView.drawTool = ToolTypePen;
        self.drawingView.lineWidth = 7;
        self.drawingView.lineAlpha = 1.0;
        self.potlood02.hidden=NO;
        self.kwast02.hidden=YES;
        self.gum02.hidden=YES;
        break;

    case 1:
        self.drawingView.drawTool = ToolTypePen;
        self.drawingView.lineWidth = 20;
        self.drawingView.lineAlpha = 0.67;
        self.potlood02.hidden=YES;
        self.kwast02.hidden=NO;
        self.gum02.hidden=YES;
        break;

    case 6:
        self.drawingView.drawTool = ToolTypeEraser;
        self.drawingView.lineWidth = 20;
        self.potlood02.hidden=YES;
        self.kwast02.hidden=YES;
        self.gum02.hidden=NO;
        break;
   }
 }

1 个答案:

答案 0 :(得分:0)

要更改铅笔图像的颜色,您可以执行以下操作

UIImage *originalImage = [UIImage imageNamed:@"PencilImage.png"]; 
UIImage *newImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,50,50)]; // your pencil image size
imageView.tintColor = [UIColor redColor];  // or whatever color that has been selected
imageView.image = newImage;

希望这有帮助。