Change background with an image stored in the iOS device on button's action - iphone

I'm developing a messaging app and I want to change the background image of the chat window on tapping the button (like Whatsapp) with an image stored in the device. Can anybody help me in writing code for that purpose?. Thanks!

First of all, you need to create a button, either from XIB/NIB or through code. On the action of that button, you need to change the background image of your view controller's view. Following code may be helpful for you.
-(void)changeBackgroundImage
{
self.objImageView.image = [UIImage imageNamed:#"imageName.png"];
}
objImageView is the object of UIImageView on which you have to show the image.
imageName.png is the name of the image which you want to show on the UIImageView.

Related

UITapGestureRecognizer is not working when tapping on image of UIImage view

I create a log in view with func that I can pick profile pic when tap on Avatar as UIImage view, you can pick avatar from library.
As the code I wrote, I am not able to trigger the tapping gesture.
Please be advised on this. Thanks
By default UIImageView has disabled user interaction. Make sure it is enabled - either in Storyboard or programmatically.

how to add in uiview for images to button programmaticaly in iphone

im new to iphone development.here i added some images to button in uiview programmaticaly in iphone. Here my problem is i want to add some more images in uiview. i added next and previous buttons in view .if click nextbutton some more will displayed in next view. i tried but i dont no how to displayed programmaticaly some more images when i click nextbutton in iphone.
can any one plz help me for my problem.
Thank you in advance.
Add a UIImageView to the view and then do:
myUIImageView.image = [UIImage imageNamed:#"anImageInMyBundle"];
Now, if you want to have a bunch of images and go through them systematically, you have a few options. This is going to depend on what your app actually does.
If you're displaying local images that are in your bundle, you can just create an NSArray (mutable or immutable - per the situation) and add all your UIImages to it at run time.
If your app downloads data from the web, you're probably going to start making network calls in a secondary thread that downloads and sets the next image. Give us a better idea of what your app does, and we might be able to provide more specific code/examples.

how to reload a view again and again

hi i am a new iphone programmer
i am creating a imagedisplay type application where i have to display images on a view and by presssing a next button a new image should appear on same view (i am using database)...
therefore i need to reload my current view again and again...each time when i click that button....
i tried some suggesion which are given on this website but not satisfied because many of them are based on timer...
please help.....
May be I have missed something in your question. But why you need to reload the entire view? You are using an UIImageView to display your image, right? And you are not showing any kind of scroll, but only a next button, right? Then why don't you just set the image property of UIImageView when the button is tapped.
// in button handler
myImageView.image = [UIImage imageNamed:#"new_image.png"];
Perhaps you could use a paged UIScrollView with three uIImageViews and always have the previous, current and next image loaded. This way when the user hits next, it scrolls animated to the next image. When page 3 is loaded, it programmatically sets the second image view as the desired next image, sets the image you came from on the first image view, and sets the scroll view non-animated to page two and loads the next image in the third image view.
Sounds complicated but basically you are giving the appearance of an infinite scroller but only pulling one image at a time except for initial load of three.
You could try looking at the "PageControl" Example Project in the XCode Documentation. It should give you a good starting point.

Changing image property upon button press

i have a UIImageView displayed in my view with an image "image1" already set.
I have a button below it.
During runtime i would like the image to change to "image 2" when the button is pressed and upon release i would like the image to display "image1" again
1) I know that i have to give the UIImage a label or something so that i can access it from xcode.
2) i know that i need to change the propery of the image upon press
3) i need to have an IBAction or something so that when i press the button it should change the property of the image to "image2"
BUT i dont know how to do this?
Can someone help please?
You need an outlet in your controller that is connected to the image view, so that the controller can find and message the image view. Check out this tutorial, and the Interface Builder documentation.

How to add image in UIActivityIndicatorView

i want to add image into initWithActivityIndicatorStyle instead of using the others like
UIActivityIndicatorViewStyleWhiteLarge. So, when come to loading page, the image will act as
image loading.
Any help, i am truly appreciate it . ^^
Thanks
You can't do that. UIActivityIndicatorView draws the system activity indicators. If you want to display a custom image then you shouldn't be using a UIActivityIndicatorView. Either create a custom view, or if you just want to display an image use a UIImageView. UIImageView also supports animating several images in a loop if you want to do that.