Please let me know if it's possible in iOS? if yes then please provide me help. I am new in iOS and i am developing an application.i want change image color not image when user taps on color button(there may be manny option to choose color)
如果在iOS中可以,请告诉我?如果是的话请给我帮助。我是iOS的新手,我正在开发一个应用程序。我希望当用户点击颜色按钮时更改图像颜色而不是图像(可能有manny选项来选择颜色)
5 个解决方案
#1
1
You can do like this way but your image must be png,
你可以这样做,但你的形象必须是png,
UIImage *img = [UIImage imageNamed:@"ic_email_white_48dp_2x.png"];
self.myImageView.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.myImageView.tintColor = [UIColor blackColor];
My image is white and when i set tintcolor it's got black. likewise you can set different different colors. UIImageRenderingModeAlwaysTemplate
is heart of this functionality.
我的图像是白色的,当我设置tintcolor它是黑色的。同样,你可以设置不同的颜色。 UIImageRenderingModeAlwaysTemplate是此功能的核心。
Hope this will help. :)
希望这会有所帮助。 :)
#2
0
No, you should use different images, and switch images according to selected color button. Prepare different images, using tools like Adobe Photoshop or similar, and upload them to XCode. Then, when user select buttonColor1, you use self.imageView.image = [UIImage imageNamed:@"redColor"]; for example..
不,您应该使用不同的图像,并根据所选的颜色按钮切换图像。使用Adobe Photoshop或类似工具准备不同的图像,然后将它们上传到XCode。然后,当用户选择buttonColor1时,使用self.imageView.image = [UIImage imageNamed:@“redColor”];例如..
#3
0
You have to add an action to a button and an outlet to the imageview. Within the button action you set the image to the imageview. f.e.
您必须向按钮和图像视图的插座添加操作。在按钮操作中,您将图像设置为imageview。 F.E.
action redbutton{
imageview.image = UIImage("greenimage.png")
}
action redbutton{
imageview.image = UIImage("redimage.png")
}
This is no correct code. Just to give you the idea.
这不是正确的代码。只是为了给你这个主意。
Edit: To make it clear. You can't change the "UIColor" of a picture to get the results you are looking for. You need different images for every color you want to have for your shirts and you just implement the change of the image within the action method of the button.
编辑:说清楚。您无法更改图片的“UIColor”以获得您要查找的结果。您需要为衬衫的每种颜色使用不同的图像,并且只需在按钮的操作方法中实现图像的更改。
#4
0
As @Anton and @David have said, changing a UIImage colour is not possible. Only way to do this would be to add separate images of the different colour variants sadly.
正如@Anton和@David所说,改变UIImage颜色是不可能的。唯一的方法就是遗憾地添加不同颜色变体的单独图像。
#5
0
You can try using the base image as a template image, and then change the tint color accordingly. For the kind of use case you have, this might not look good enough for your needs, but you can try. It will depend on your original base image.
您可以尝试将基本图像用作模板图像,然后相应地更改色调颜色。对于您的用例,这可能看起来不够满足您的需求,但您可以尝试。这取决于您的原始基本图像。
To set the original image:
要设置原始图像:
if let tshirtimage = UIImage(named: "tshirtbase") {
imageView.image = tshirtimage.imageWithRenderingMode(.AlwaysTemplate)
}
Then, in the button code for each color, you can change the color like this:
然后,在每种颜色的按钮代码中,您可以更改颜色,如下所示:
imageView.tintColor = UIColor.redColor()
#1
1
You can do like this way but your image must be png,
你可以这样做,但你的形象必须是png,
UIImage *img = [UIImage imageNamed:@"ic_email_white_48dp_2x.png"];
self.myImageView.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.myImageView.tintColor = [UIColor blackColor];
My image is white and when i set tintcolor it's got black. likewise you can set different different colors. UIImageRenderingModeAlwaysTemplate
is heart of this functionality.
我的图像是白色的,当我设置tintcolor它是黑色的。同样,你可以设置不同的颜色。 UIImageRenderingModeAlwaysTemplate是此功能的核心。
Hope this will help. :)
希望这会有所帮助。 :)
#2
0
No, you should use different images, and switch images according to selected color button. Prepare different images, using tools like Adobe Photoshop or similar, and upload them to XCode. Then, when user select buttonColor1, you use self.imageView.image = [UIImage imageNamed:@"redColor"]; for example..
不,您应该使用不同的图像,并根据所选的颜色按钮切换图像。使用Adobe Photoshop或类似工具准备不同的图像,然后将它们上传到XCode。然后,当用户选择buttonColor1时,使用self.imageView.image = [UIImage imageNamed:@“redColor”];例如..
#3
0
You have to add an action to a button and an outlet to the imageview. Within the button action you set the image to the imageview. f.e.
您必须向按钮和图像视图的插座添加操作。在按钮操作中,您将图像设置为imageview。 F.E.
action redbutton{
imageview.image = UIImage("greenimage.png")
}
action redbutton{
imageview.image = UIImage("redimage.png")
}
This is no correct code. Just to give you the idea.
这不是正确的代码。只是为了给你这个主意。
Edit: To make it clear. You can't change the "UIColor" of a picture to get the results you are looking for. You need different images for every color you want to have for your shirts and you just implement the change of the image within the action method of the button.
编辑:说清楚。您无法更改图片的“UIColor”以获得您要查找的结果。您需要为衬衫的每种颜色使用不同的图像,并且只需在按钮的操作方法中实现图像的更改。
#4
0
As @Anton and @David have said, changing a UIImage colour is not possible. Only way to do this would be to add separate images of the different colour variants sadly.
正如@Anton和@David所说,改变UIImage颜色是不可能的。唯一的方法就是遗憾地添加不同颜色变体的单独图像。
#5
0
You can try using the base image as a template image, and then change the tint color accordingly. For the kind of use case you have, this might not look good enough for your needs, but you can try. It will depend on your original base image.
您可以尝试将基本图像用作模板图像,然后相应地更改色调颜色。对于您的用例,这可能看起来不够满足您的需求,但您可以尝试。这取决于您的原始基本图像。
To set the original image:
要设置原始图像:
if let tshirtimage = UIImage(named: "tshirtbase") {
imageView.image = tshirtimage.imageWithRenderingMode(.AlwaysTemplate)
}
Then, in the button code for each color, you can change the color like this:
然后,在每种颜色的按钮代码中,您可以更改颜色,如下所示:
imageView.tintColor = UIColor.redColor()