Can't set Background for buttons iOS - ios

I made a simple app using the storyboard feature. I have made some UIButtons and I want to change the background of my UIButtons. In the storyboard the background successfully changes but in the actual iOS simulator my background does not change.

Here are some suggestions for you:
If you set image programatically than check image name spelling, It should be match exactly with bundle image name(case sensitive).
You have to add two images in your bundle. e.g if image name is nature.png than you must have to add nature.png and nature#2x.png(#2x image must have double size than normal).
Although if you are using only one image for retina devices than check that you run your application in only retina devices, Sometime non-retina device won't show image.
If you set image as UIButton image with title than it is requited to set title and image insets, If title text is big or image size is bigger.

Related

Different background Image for Splash Screen for iPad for Landscape & Potrait Mode in LaunchScreen.storyboard

I need to set a different background image for iPad for both Landscape & Portrait mode in LaunchScreen.storyboard. I am unable to do that using size-classes as both of them have Regular-Regular size classes. Is there any way to do so? I have other UIKit elements in the LaunchScreen.storyboard as well. like another Imageview and Labels.
you can follow this answer
You can use a single Storyboard to load different Launch images for
iPad and iPhone. In your LaunchScreen.storyboard, go to the Attributes
Inspector of the ImageView where you set the image. Set launch image
for iPhone in Image field. There is a plus sign near the "Image"
field. Click on it and change the Height from Compact to Regular and
click Add Variation. Another field is created as wR hR. Add the launch
image for iPad there. Thats it. Now it loads launch image based on
your device.

Xcode changing a button background image for various devices

How can I change button background image - I need one for all iPhones and another (due to size) for iPads. I have square buttons imitating keyboard with smaller background image. On iPad font on buttons is twice bigger, but they are not squares anymore. So I made bigger backgroud image to make them squares again, but how can I change that image only for iPads in storyboard. Is it possible?
Thanks.
on iPhones:
on Ipads:
You can design the layout using size class. The size class for iPad is R*R.

iOS : How using different size image with the same name in Assets.xcassets when Running on different device or different landscape

Purpose
I am to make my iOS app run on the different device include iPhone and iPad.
I want to setup the ImageView's image with different size using the same name for Adapting to the different devices and landscape.
What I am doing
1.import image into Assets.xcassets for different device traits.
apple program reference: Create asset variations for different device traits
The image inside xcodes' Assets.xcassets has different width or height class setting. I name the image after "homeBackground"
The image like this :
[1]: https://i.stack.imgur.com/yXHk4.png
2. drag the imageView into Interface Builder
3. set the imageView's attributes: Image in the Interface Builder as the image's name "homeBackground"
4. view as iPad or iPhone
using xcode 8.3. I can preview the scene.
I can see the imageView's image is set successfully, When viewing as Ipad or iPhone
Problem
run the app in xcode. I don't see the imageView has the image in the simulator and I have the following question:
Could not load the "homeBackground" image referenced from a nib in the bundle with identifier "BTBubblePop"
complete
I run it in the iPad, the ImageView's image shows
I run it in the iPhone, the ImageView's image don't show.
thanks for your focus and comment.
the question is called by the image not set correctly.
The image's assets.xcassets change like this. That's worked.
The Image should like these.
Image should set like here
If I understand your question correctly the answer is that it goes by image set name.
Or in code
UIImage *image = [UIImage imageNamed:#"homeBackground"];
[[UIImageView alloc] initWithImage:image];

UIButton image. Auto size to real image size. Device based

I have a universal application.
I have a main menu with 2 buttons. The button have a different size\shape on ipad and on iphone.
btn_main_all#2x~ipad.png
btn_main_all.png
I'm using xcode filename to get the good image from each device(work great). But the image are not resized to the good specific size. (i've try each combinaison in storyboard... top left, fit..., etc.
How can I have the button to get the real image size ?

Unable to properly load iPhone 4" image

My application, which should support iOS 5.0+ I have background UIImage, which should be load proper image depending on device. So I've created 5 images with corresponding resolutions.
img.png
img#2x.png
img-568h#2x.png
img~ipad.png
img#2x~ipad.png
Also I've set Default-568h#2x.png splash image. I then detect in viewDidLoad which device my app is running and use
[bkgImageView setImage:[UIImage imageNamed:#"img.png"]];
to load appropriate image. All resolutions are loading just fine except iPhone 4" one, which is img-568h#2x.png. If I load this one explicitly
[bkgImageView setImage:[UIImage imageNamed:#"img-568h#2x.png"]];
the scale is not correct. So how can I load 4" retina image automagically or manually?
Adding -568h to the end of the file name doesn't work. The only supported modifiers are #2x,~ipad, and ~iphone. The only case where -568h might seem to work is the launch image, where the image must be specifically named Default-568h#2x.png.
You should use auto layout (or struts and springs) to adjust your screen accordingly.
Your problem is that it's automatically stretching an image that's already large enough.
The solution:
If you load the image explicitly for that device, you should load "image-568h", and let it automatically add the #2x. That way, it knows that it's a high resolution image and doesn't attempt to stretch it.
Additionally, rather than detect the device, you could design the image with the extra space at the bottom to fit the 4" screen, set the image to Aspect Fill, and let it clip for smaller devices.

Resources