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?
IBOutlet UIImageView *imageView;
imageView.image=[UIImage imageNamed:#"img.png"];
[imageView setNeedsDisplay];
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"];
Create an IBOutlet using
IBOutlet UIImageView *myImageView;
Hook this up with your xib file in interface builder and change the image with
myImageView.image=originalImage;
[myImageView setNeedsDisplay];
You can use myImageView to refer to that image view in IB.
Can you just set the image property of the UIImageView to the original image.
UIImageView *imageView = [UIImageView new];
[imageView setImage:origingalImage];
Related
In my .h file I have:
IBOutlet UIImageView *image1;
and in .m file I am trying to assing image to this image1 like this
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
But the UIImageView is not showing anything. Its blank.
What can be the problem.
If you have an IBOutlet attached to your property , you do not need to allocate and initialize the imageView again.
Just try :
image1.image = [UIImage imageNamed:#"Blue-Jaanamaz-Small"];
Also use this if your imageView is not on the top of your view hierachy.
[self.view bringSubviewToFront:image1];
Make sure that your imageView is not hidden in InterfaceBuilder or somewhere in code.
And make sure your IBOutlet is correctly connected to an imageView in the InterfaceBuilder.
Check the connections between Interface builder and UIImageView.
I have an app that I am working on, and in an effort to save on views that I make, I want to be able to dynamically pass the view an image. So for example, I make a view:
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
Then I want to set the image that the view's imageview shows before I present it:
UIImage *image = [UIImage imageNamed: #"IMG_5010_2.jpg"];
[controller.imageView setImage:image];
[controller.label setText:#"HI"];//I am trying to do this too and it isn't working...
But it just isn't working!! Does anyone have any thoughts on this? Please help!!
Thanks
NOTE: I do have UIImageView and UILabel attributes set on the view I am trying to present...
You should set the image within viewDidLoad method of the relevant UIViewController as the view won't exist during the init phase and will have been displayed by the time viewDidAppear is called.
Perhaps you could try this:
add two new properties to your FlipsideViewController:
#property (retain) UIImage *image;
#property (copy) NSString *labelText;
Don't forget to synthesize them in your FlipsideViewController.m.
Then when you instantiate your FlipsideViewController:
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
UIImage *image = [UIImage imageNamed: #"IMG_5010_2.jpg"];
controller.image = image;
controller.labelText = #"Hi";
and then in your FlipsideViewController viewDidLoad method you can assign the values in the properties to the view IBOutlets:
- (void)viewDidLoad {
//do other stuff
[self.imageView setImage:self.image];
[self.label setText:self.labelText];
//any other stuff
}
Sure you've got your IBOutlets hooked up properly in the nib file?
Assuming you've put this code in the right place in your view controller, this should be working fine. So it's either you're not in a place that this code is getting run, or the things you're configuring aren't hooked to any objects in the nib. It has to be one of those two things.
I want to change image in image viewer when I click a button.
I know this question basic but, I need an answer for this.
Please reply
First, implement the following method in a MyViewController.m (also, add method signature to MyViewController.h file):
MyViewController.m:
- (IBAction)handleButtonClick:(id)sender {
imageView.image = [UIImage imageNamed:#"blah.png"];
}
MyViewController.h:
{
IBOutlet UIImageView *imageView;
}
- (IBAction)handleButtonClick:(id)sender;
Then attach handleButtonClick action to button's Touch up inside event and imageView outlet to your image view in Interface builder.
Voila.
I have this code:
- (void)viewDidLoad {
[super viewDidLoad];
landscape.image = [UIImage imageNamed:#"tenerife1.png"];
}
First, I created an UIImageView with IBOutlet. Landscape is pointing to that UIImageView. In InterfaceBuilder I told to show an specific image in that UIImageView. It never changes. I always see the image I specified in InterfaceBuilder. But I want to set it programmatically. How can I do this?
Try calling setNeedsDisplay on the view after you change the image:
[landscape setNeedsDisplay];
Add this code, it might help you:
-(void)viewDidAppear:(BOOL)animated
{
landscape.image = [UIImage imageNamed:#"tenerife1.png"];
}
is it possible you did not have a custom view set up for that nib file? I had the same problem. I created a UIview subclass for that view controller, went into Interface Builder and set the view to that UIView subclass and then added an import header for the UIView into the Controller class. thats what did it for me
Don't forget about connection between imageview and File's Owner in InterfaceBuilder.
it's only you need after that:
landscape.image = [UIImage imageNamed:#"tenerife1.png"];
My problem is that I can't seem to get the image from my bundle to display properly. This method is in the view controller that controls the tableview. headerView is loaded with the tableview in the .nib file and contains a few UILabels (not shown) that load just fine. Any ideas?
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] setTableHeaderView:headerView];
NSBundle *bundle = [NSBundle mainBundle];
NSString *imagePath = [bundle pathForResource:#"awesome_lolcat" ofType:#"jpeg"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
imageView = [[UIImageView alloc] initWithImage:image];
}
If you've already created an outlet and connected it to a view in Interface Builder, you should use that view, rather than creating a UIImageView on the fly.
//this assumes that headerView is an already created UIView, perhaps an IBOutlet
//also, imageViewOutlet is an IB outlet hooked up to a UIImageView, and added as
//a subview of headerView.
//you can also set the image directly from within IB
imageViewOutlet.image = [UIImage imageNamed: #"awesome_lolcat.jpeg"];
[[self view] setTableHeaderView: headerView];
FIrst you need to figure out whether your image is loading properly. The quickest way to get an image is to use the UIImage convenience method +[UIImage imageNamed: rawImageName].
Also, is this a UITableViewController? (it's unclear, but implied).
Where is imageView being used? You create it near the bottom, but don't seem to do anything with it. You probably want to create the image view, assign it an image, and then add it as a subview to the headerView.
//this assumes that headerView is an already created UIView, perhaps an IBOutlet
UIImage *image = [UIImage imageNamed: #"awesome_lolcat.jpeg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
[headerView addSubview: [imageView autorelease]];
[[self view] setTableHeaderView: headerView];
Adding the subview programatically worked, but it isn't correctly linked to the UIImageView in Interface Builder. The view I created is (I think) correctly linked to the UIView outlet in my UITableViewController, but when I init my imageView it creates a new view instead of putting the image in the view I already created.
Thanks for your answer.
See http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
It will display UIImageview on section header.