ios 如何在不加载整个视图的情况下重置 UIImageView 中的图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8589283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reset the image in UIImageView without loading the whole view?
提问by Naveen Chauhan
I have a xib which has 1 UIImageView and 1 Toolbar.
Toolbar has two buttons save and reset.
In the simulator i can make some drawing on the image in the UIImageView.
Now i want that if i click on the reset button then i would get the original image if i didn't save the changes on the image.
I don't want to load the entire view again.
Only I need to replace my edited image with original image?
Can you please guide me that how can i do this stuff?
我有一个包含 1 个 UIImageView 和 1 个工具栏的 xib。工具栏有两个按钮保存和重置。
在模拟器中,我可以在 UIImageView 中的图像上进行一些绘图。现在我想要,如果我点击重置按钮,那么如果我没有保存对图像的更改,我将获得原始图像。我不想再次加载整个视图。只有我需要用原始图像替换我编辑过的图像吗?你能指导我如何做这些事情吗?
回答by
IBOutlet UIImageView *imageView;
imageView.image=[UIImage imageNamed:@"img.png"];
[imageView setNeedsDisplay];
回答by dayitv89
UIImageView *imageView;
imageView.image=[UIImage imageNamed:@"one.png"];
refresh with orignal image. Have u tried this
用原始图像刷新。你试过这个吗
[imageView reloadInputViews];
If it not work try this code again to refresh
如果它不起作用,请再次尝试此代码以刷新
imageView.image=[UIImage imageNamed:@"one.png"];
回答by MadhavanRP
Create an IBOutlet using
创建一个 IBOutlet 使用
IBOutlet UIImageView *myImageView;
Hook this up with your xib file in interface builder and change the image with
将其与界面构建器中的 xib 文件连接起来,并使用以下命令更改图像
myImageView.image=originalImage;
[myImageView setNeedsDisplay];
You can use myImageView
to refer to that image view in IB.
您可以使用myImageView
指代 IB 中的图像视图。
回答by Jordan
Can you just set the image property of the UIImageView to the original image.
您可以将 UIImageView 的图像属性设置为原始图像。
UIImageView *imageView = [UIImageView new];
[imageView setImage:origingalImage];