Image not appearing in UIImageView - iphone

I have a UIImageView in Interface Builder connected to an outlet called imageView. The statement
[imageView setImage: [UIImage imageNamed: #"xxxx.png"]];
displays an image successfully if placed in viewDidLoad, but NOT if placed in an action method in the same view controller. There's an NSLog in the action method so I know it's firing.
I've looked at the other "UIImageView not appearing" questions but none of them seem directly relevant. Any help would be much appreciated!
Thanks,
Mark

Try forcing a redraw:
[imageView setNeedsDisplay];

Related

Expandable UITextField with option for inserting image

I want to make the same view as iPhone default message app here is the screen shot what i want to do so can any one help me for suggesting 3rd party control or technique for making this kind of control in my app
Here is the Source code you wanted for the Growing TextField , although it doesn't contains the image button but you can easily customize it to fullfil your requirement
https://github.com/HansPinckaers/GrowingTextView
Hope it will help you.
You can add the image view as a subView of UITextView.
Create an imageView with image:
UIImageView *imageView = [[UIImageView alloc] initWithImage:yourImage];
[imageView setFrame:yourFrame];
[yourTextView addSubview:imageView];
and can use third party library for this Here
Hope it helps you.
you can directly add your image view on text view.
Tried this one
UIImageView * image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#"xyz.png"]];
[textview addSubview:image];
this will really helpful.

Issues setting up a back ground image and with UIImageView

On my iPhone app, I simply want to set a particular background image, which depends on whether it's an iPhone 5 or not.
So, I tried two approaches:
A) Using
self.view.backgroundColor = [UIColor colorWithPatternImage:backGroundimage];
B) Creating an UIImageView and setting up the image there. Code:
UIImageView *backgroundImageView = [[UIImageView alloc]initWithFrame:screenBounds];
[backgroundImageView setImage:[UIImage imageNamed:backGroundImage]];
[self.view addSubview:backgroundImageView];
But I am having issues with both of them:
Issues with Step A:
When I set the image through that way, I have to deal with the image scaling issues for different sizes of the screen. I use the following code to do the scalling:
UIGraphicsBeginImageContext(screenBounds.size);
[[UIImage imageNamed:backGroundImage] drawInRect:screenBounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
Another issue from Step A is that the image appears quite blurry. It doesn't have the same sharpness to it.
Issues with Step B:
With this, the image looks really crisp and sharp - just the way it should look.
But when I switch to another view using the following code, strangely enough the UIImageView backgroundImageView still appears on the second one. The code I use to switch views is:
[self presentViewController:secondViewController animated:YES completion:nil];
I even tried [backgroundImageView removeFromSuperview], but that doesn't solve anything either.
So what am I doing wrong? And how can I set up a picture as my background which is dependent on the size of the iphone?
Plan B is a good plan. Presenting another view controller should and will definitely hide your image view. If it isn't happening, then it's a problem with the creation of secondViewController, unrelated to the background image on the presenting VC.
Before presenting secondViewController, log it:
NSLog(#"presenting %#", secondViewController);
I'll bet a dollar that it's nil. If I'm right, let's have a look at how you initialize secondViewController. That's the problem, unrelated to the background image view.
Okay, I finally fixed this issue, although the cause of this issue is still puzzling to me.
To fix this, I had to create an IBOutlet property for UIImageView and hook it up on the XIB file.
The reason I was programmatically creating the UIImageView is because the size of the UIImageView depends on what size iPhone they are using. But for the IBOutlet (let's call it as UIImageViewOutlet, I simply used [self.UIImageViewOutlet setFrame:] to get the size and location that I wanted.
I also discovered that one of the buttons that I was programmatically creating, was still visible in the secondViewController. I ended up creating an Outlet on the XIB file for that one as well and used setFrame on it to position it properly.
If anyone who knows the reason of this problem, I will be very grateful.

UIPickerView not showing up

I have a UIPickerView that wont show up when I run the app because I created it programmatically and I'm using a UIImage as a background for the app. How can I get it to show up ? I have tried
[super.view sendSubviewToFront...];
and it still doesn't show up. Any idea why?
I dont have my Mac rite now but ill give you the basic idea . What you should really do is after allocating both the image and the pickerview ; first addSubView the UIImage onto the self.View and then addSubView the UIPickerView on the UIImage like
[self.View addSubView:image];
[image addSubView:pickerView];
Any doubt let me know . Thanks .

ImageView Send to Back Programmatically

After trying all the methods in the previous post I am not able to succeed sending my ImageView back to my Oscilloscope. I am using aurioTouch sample of Apple's example in my app and I have just resized the image in that.. Now I want to have another image in the same view. In my applicationDidFinishLaunching in the beginning I am writing the below code
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myImage.png"]];
[imgView setFrame:CGRectMake(0,25,320,150)];
[view addSubview:imgView];
after this much of code i tried all the methods that is given in previous post but not able to get this newssmage behind the original image..
Here view is one of the class inherited from UIView.. How can I send new image back to my original image???
One look at the documentation for UIView would give you a list of possible methods to influence the view hierarchy. Some of them are:
– bringSubviewToFront:
– sendSubviewToBack:
– removeFromSuperview
– insertSubview:atIndex:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– exchangeSubviewAtIndex:withSubviewAtIndex:
you need to call
- (void)sendSubviewToBack:(UIView *)view
on the view object in your code like this
[view sendSubviewToBack: imgView];
EDIT:
I have seen the code and from the looks of it the the image "Oscilloscope.png" is added on the EAGLView object with variable name view and if I am correct the you are using the same variable to add your imgView too, so I think it should work.

Touch Event on image , achieved by using UIButton but show up delayed compare to UIImageView

Sorry for the messy title, I just don't know how to describe the problem in a delicate way.
I'm writing a album-like app to display a bunch of image in my scrollview and do something when a image is touched.
I followed this question : how can i detect the touch event of an UIImageView and use button with background image to handle touch event.
My original method is using NSOperation to concurrently fetch image from internet and put it io a imageview and add to my scrollview, and the speed is quite ok because each imageview shows right after each NSOperation callback.
Then I change imageview to uibutton, the strange thing is that when a NSOperation callback, that button does not show in my view. They show up at once when all the NSOperation callback is done. That makes the user experience become unacceptable.
This is my NSOperation callback function, it will pass a button that contains the image fetched from internet
- (void)imageLoaded:(UIButton*)button;
{
NSLog(#"Done");
[button addTarget:self action:#selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
The buttons will only displa after the last "Done" appear instead of one by one, is that normal? or I messed up something?
==== update ========
I think I'm running the NSOperation on my viewcontroller. I have a imageLoadOperation class, I'll pass my viewcontroller to it
imageLoadOperation *ilo = [[imageLoadOperation alloc] initWithURLString:[NSString stringWithFormat:#"link for the image"];
[ilo setParent:self];
[queue addOperation:ilo];
[ilo release];
And in the main function of imageLoadOperation I'll do
[parentViewController performSelectorOnMainThread:#selector(imageLoaded:) withObject:button waitUntilDone:NO];
Do you mean I need to move these code to my AppDelegate instead of running in my viewcontrollor?
You can use a button of custom type over your image view instead of using button with background image, or you can use touch event on an UIImageView
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
What if instead of converting to a button you just allowed your UIImageView to handle the touch event?
To add a touch event to a UIImageView use the following format in your .m
UITapGestureRecognizer *newTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(newTapMethod)];
[_imageButtonName setUserInteractionEnabled:YES];
[_imageButtonName addGestureRecognizer:newTap];
then create the newTapMethod (or what ever you name it)
-(void)newTapMethod{
//...
}
hope that helps.