IOS / Objective-C:更改图像视图的色调

时间:2017-07-07 20:33:18

标签: ios objective-c

我想在用户触摸时更改图像视图的颜色。我不需要它改变很多。但是,我希望它变成蓝色。我找到了以下代码来更改渐变,但它没有任何效果。我不需要渐变,实际上只需要一种色调。非常感谢任何建议。

 UIView *snapshot = [[UIImageView alloc] initWithImage:image];
        snapshot.layer.masksToBounds = NO;
          CAGradientLayer *gradient = [CAGradientLayer layer];

        gradient.colors = @[(id)[UIColor redColor].CGColor, (id)[UIColor blackColor].CGColor];

        [snapshot.layer insertSublayer:gradient atIndex:0];

2 个答案:

答案 0 :(得分:1)

你可以尝试给UIImage一个色彩

Sub SendBasicEmail()
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
    .BodyFormat = olFormatHTML
    .Display
    .HTMLBody = "<h3>Testing</h3><br>" & "<br>" & .HTMLBody
    .Attachments.Add "xxx/test.pdf"
    .To = ""
    .BCC = ""
    .Subject = "Test Message"
    '.Send
End With 
End Sub

然后在用户使用轻击手势识别器触摸图像时更改该色调

答案 1 :(得分:1)

简单且非侵入性的方法是在图像视图中添加半透明叠加层。然后,当按下并释放按钮时,可以显示和隐藏它。

- (void)indicatedImageViewPressed:(UIImageView *)imageView on:(BOOL)on {
    UIView *overlay = [imageView viewWithTag:1]; // See if already created
    if (overlay == nil) {
        overlay = [[UIView alloc] initWithFrame:imageView.bounds];
        overlay.tag = 1; // Mark view to find it next time
        overlay.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.3]; // Your color overlay goes here
        [imageView addSubview:overlay];
    }
    overlay.hidden = !on;
}