How to display background image or foreground image of an iphone app - iphone

This might come across as a very silly question. I am trying to place an image behind my first "Hello World" app on iphone, since this morning. I tried doing so using Interface Builder using UIImageView object from library and also tried doing so programmatically.
Googling hasn't be much of an help either. Can any one please demonstrate a simple app that shows how to display an image in an iphone app, in background and/or in foreground?

The step you're missing is likely adding the image to the project.
Drag an image from the finder to the Resources section of the project outline. Xcode infers the action from the file type, and images will be copied to the Resources folder. You can check it out in the Targets section of the project outline, if you disclose your Hello World target you'll see the different build phases, including a "Copy bundle resources" build phase.
Anyway once the image is added to your project, the UIImageView inspector image name will autocomplete your image name, and all should work. No code needed.

You could try to add a UIImageView, in IB, to your view and arrange it to the background (behind all labels, etc)
edit: I just realized, you already tried it in IB. I was ignorant, I'm sorry.
The thing is, I do this same trick myself, and it works. If you add a UIImageView to your view in IB, what happens? Does it stick to the foreground? If so, you can re-arrange the position of the object by using the 'Layout' menu.
edit2: I just searched the iphone reference library, and the "Hello World" example also shows how it is done. (http://developer.apple.com/iphone/prerelease/library/samplecode/HelloWorld/index.html)

Related

Is there a way to insert an image in Xcode?

I'm very new to Xcode and Swift, so for now I'm creating a UI that requires an image to appear on the screen. I would like to add the image to the LaunchScreen.storyboard file in Xcode. Can anybody help me?
I'm very new to Xcode and Swift, so for now I'm creating a UI that requires an image to appear on the screen. I would like to add the image to the LaunchScreen.storyboard file in Xcode. Can anybody help me?
Images are typically stored in .xcassets files, which show up as folders in your project. Your project probably already has one called Assets.xcassets, and you can just drag and drop images into that file. Then you can add an image view to your LaunchScreen.storyboard and set it to use the image you just added.
Beyond that, let me suggest that you go through some of Apple's SwiftUI tutorials. They'll help you learn about Swift, but you'll also get a lot of exposure to just using Xcode. If you have to figure it all out on your own, it'll take a lot longer.

Using One UIImageView that Changes Based on Button Pushed

This is a very basic question, but I cannot figure this out. I'm new to iOS/XCode. I've gone through a few tutorials that somewhat covered this (but a little more complex). I have an Android app that I'm trying to port over to iOS. I'm using storyboards for this app.
The basic premise is that the app contains 27 thumbnail/full images. For this question, we'll say the 27 pictures are split into 4 categories: cats, dogs, sharks, whales. Currently, I have the app launching with Navigation Controller w/ View that shows 4 Buttons with these categories. These push out to 4 separate view controllers each set up with buttons with the thumbnail as the image. I want to select the thumbnail and show a scene with the full image. I only want one full image view controller with a UIImageView in it that will display the full image of the thumbnail pressed. (Using table views may be easier, but I want to control the user interface and have more than just a rows of items to select.) Also, I'm not sure if this matters in the eventual set up, but from the full image scene I will want to add a play button that will play a local mp4 file (but that's for another day).
The image set will remain static so I was trying to incorporate NSArray with the full image name stored. I believe I have to add a file that is subclass of ViewController and incorporate code that will take on the full image file name based on the button pushed. This is where I'm stuck. In java for Android, I just had listeners on each button and used a case statement to set the full image variable and passed it to my full image class/xml.
Another option I think I remember seeing somewhere is I could use the title of each button and enter the full image name there. Then when the button is pressed, the title is passed to the full image view. I think this eliminates the need for an array (???).
Any help is appreciated.
Thanks,
Jason

How can I prevent Xcode from changing the color of my buttons?

So I've done a button for my iPad app, and I saw something strange. When I run my app in the iOS 5 simulator, it changes the color, and the lines of my button become discontinuous. But when I push it, the button comes back to the right color, and the lines are ok. I think it's something that Xcode does automatically with any button, and I don't find the way to cancel it. Thank you for helping!
PS: The button code is so simple:
IBOutlet UIButton *button;
This is what it should look like:
And this is how it looks in the simulator:
Both tams and JacobFennell have good points, but you should also note that graphics are often represented much differently on the simulator than on a real device. You should try running your app on a device and see if the problem persists; I have had many 'problems' with custom buttons which turned out just to be improper rendering on the part of the simulator.
Since you are using the Interface builder, make sure that you are setting the button type to custom and that you have changed the behavior for all of the states. Under the dropdown menu of where you can set the type they also have StateConfig, where you can configure the look and text of your button for all of its different states: highlighted, default, disabled...Check that those settings are correct as well.
Hope this helps!
Tams
Your button frame size doesn't seem to match the size of your image. Your art should match the (button/view) frame size pixel for pixel, otherwise you may get blurry images and scaling representation artifacts.
Else, you can change the view content mode (UIViewContentMode) of the frame from UIViewContentModeScaleToFill to UIViewContentModeTopLeft

iPhone: InterfaceBuilder nibs disconnected from my project

Since upgrading to XCode 3.2, InterfaceBuilder doesn't play nice. All of my image links are broken in IB but they'll show fine when I compile. When I go to the combo box to select an image for my UIImageView, it doesn't have the image files I've added to my app.
I also can't create a new .nib and associate it with a class I've written. Like images, my custom viewcontrollers aren't available to pick from.
I'm going to try a reinstall but I was curious if anyone's dealt with this?
I gave up trying to fix and resorted the classic workaround. Started a clean project and schlepped everything over. Things are fine...for now.

Where can I get the original images for the Accessory buttons in a UITableView?

I want to create a custom accessory icon to go to the right of my cell in a UITableView and want it to match the blue >, I have tried creating from scratch and it looks good on its own but when put next to a cell with the blue > it looks messy where the two icons look similar but not of the same style. Does anyone know where I can get hold of the original DetailDisclosure button icon so I can use it as a base for my icon? BTW tried doing a screen capture, but you don't get any transparency information with that.
Regards
Dave
Check this blog post:
http://0xced.blogspot.com/2009/04/extract-uikit-artwork.html
Put that code in a project and run it in the simulator. It will extract the artwork from UIKit and save it in the app's Documents directory. NSLog(documentsPath) to see where they're going. It will save out tons of images for pretty much everything.