Set an image as background for all screen resolutions - ios

I'm in trouble with the design part of my app and I hope someone will be able to help me. Here is the description of my problem:
I would like to put an image in background of all views of my app adapting all screen resolutions. My designer has given to me these background images in different sizes (for all devices, iPhone and iPad). I'm not using size classes because it's an old project. I have two storyboards: one for iPad devices and another one for iPhone devices. I created an UIImageView, put it on my view in storyboard and added the good constraints (stick to all sides)
I tried two methods to achieve my goal:
Using the slicing method but the problem is I have some logos on my
image and it become difficult to slice.
Using the Mode of the image in storyboard like Aspect fill, Aspect fit, Scale to fill and so on. The problem with this method is that the background seems to be good for one device, but distorted for all other devices.
I searched all over the web to find something but without success. Is someone already had this issue and found a solution ?
Thanks a lot in advance !

All you have to do is in viewDidLoad determine the screen size and set a different image; you might want to do the same if your screen is being rotated.

I think you need to use Mode property of UIView,
If you Aspect fill then your image will be set and cropped as per size, but on use of Aspect fill you need to use clipToBound to YES as well,
If you use Aspect fit then image will be display as its Aspect Ratio.
But for background the Aspect fill will be the best with clipToBound to YES

if you want to set the same background image for every viewcontroller you can try this in your appdelegate
[self.window setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"default"]]]; and set background color of your viewcontroller to clearColor,thats it. I have done the same thing in one of my application. Feel free to ask further suggestions...

Related

ios custom font with splash screen [duplicate]

I'm using a label to display text with my custom font on LaunchScreen.xib. My custom font shows up fine in the Interface Builder, but when I test it on my iPhone the font reverts back to the default font.
Not sure how to fix this or if it's a bug.
There's no big surprise here. The launch screen is shown at launch time - actually, before launch time - so the font probably hasn't yet loaded.
You could file a bug if you think you have a compelling use case. But I don't really think you do. Why are you showing any text in your launch image? It should be much more bare-bones than that - just enough to give the structure of the opening interface, which will be filled in when the opening interface actually appears. A "blank" screen with the same background color as the initial view controller's background color would be sufficient. You goal is just to provide an alternative to blackness.
A quick workaround is to use an UIImageView and have your text as UIImage on it, literally a picture of your text as .png / .jpeg or similar.
Note: It may take some time before you can see the image, I had to clean the Build Folder and reinstall the app a couple of times in order to see the image.
Another note: If you want to support multiple languages with different texts you will need to have different images for each language using this approach.

How to display different images in launch screen depending on size classes

I have a LaunchScreen.xib that needs to show slightly different logos for different device formats. I understand how to set constraints conditionally using the "Vary for Traits" button, but I also need to replace the actual image set that the UIImageView is using. I know there is some kind of workaround because I have a sample file where this is happening, but I don't know how they achieved it (see the grayed-out images in the screenshot). I cannot use code because this is a launch screen, so any solution needs to be possible with interface builder.
Conditional image use that I would like to replicate
You can have different images for iPhone and iPad (watch, TV) in your asset catalog for one resource.
You can also have different image for different width, height (traits based) and gamut that you specify in the Image drop down in the LaunchScreen.storyboard (see the little plus sign).
I think the latter is what you want.

Resolution independence in Xamarin for iOS

I'm taking a few first steps in Xamarin for iOS and having a very hard time figuring out how to create a view that is resolution independent.
I have a single textbox in the view, aligned so that its edges meet the edge of a iPhone 6S. When I change the View to a Iphone 4S the edges of the textbox are outside of the view.
I have tried to drag the constrains to the edges, pretty much clicked every button and tried to find some example of how to make it so the view resizes to fit the viewport but I cannot make it work. Ive also fiddled with the different modes of the View (Aspect Fit, Scale to Fill, etc) but that makes no difference.
I would love to se a simple example of how to create a resolution independent or multi-resolution form or view that is displayed similarily no matter the screen resolution on the iPhone.
Having gone through very much the same pain as you, my recommendation is two-fold:
Have a look at the Cirrious FluentLayouts package, which you can
get from NuGet.
A tremendous help in simplifying various issues with auto-layout, especially if you decide (like I did) to just give up on the GUI layout tools and go with a full programmatic approach.
It will allow constructs like:
this.AddConstraints
(
_navBar.AtTopOf(this, UIApplication.SharedApplication.StatusBarFrame.Height),
_navBar.AtLeftOf(this),
_navBar.WithSameWidth(this),
_navBar.Height().EqualTo(Hamburger.HamburgerHeight),
_scrollView.Below(_navBar),
_scrollView.AtLeftOf(this),
_scrollView.WithSameWidth(this),
_scrollView.Bottom().EqualTo().TopOf(_pageControl),
_pageControl.Above(_toolBar),
_pageControl.AtLeftOf(this),
_pageControl.WithSameWidth(this),
_pageControl.Height().EqualTo(pageControlHeight),
_toolBar.Above(_button),
_toolBar.AtLeftOf(this),
_toolBar.WithSameWidth(this),
_toolBar.Height().EqualTo(toolHeight),
_button.AtRightOf(this),
_button.AtBottomOf(this),
_button.Height().EqualTo(buttonHeight)
);
Be aware that since... iOS 8 I believe? ... you now need to use a
LaunchScreen.xib to have your app correctly pick up device
resolution which will then be used by auto-layout.
This was the one area I still needed to use the graphical layout tool for - just once, happy to say.

Xcode 7 Swift 2 should I use a button font or Image?

I'm totally new to Xcode and I'm trying to write a very simple app.
On my main screen, basically I load three buttons vertically/centered. I also have an Image for each button. When I press (touch down), the image changes to another image (just to show its selected).
The images that I'm using are nothing but different colored font with a border line. Should I just use the same font in the button and change it to a different color when pressed or use images to show the button is selected/unselected? Does this have an impact on the app (load image) each time a button is pressed?
Can I have different sizes of the button loaded based on different iphone? Is yes, how can I do that?
Thank you in advance.
As Wain mentioned the performance difference should be insignificant. I do agree through that changing the font color is probably easier to maintain and change in code.
Change the font in your code by using this example in your IBAction method:
labelName.font = UIFont(name: "systemFont", size: 30)
Concerning your other question about different sizes on different devices, you should do this by setting constraints. I recommended you to read Apple's auto layout guide: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html
But the essence is that you set the width and height of the button based on its distance to other elements in your UI or the edges of the screen. If you for example want your button to be 25 points from the left and right edges of the screen, this will naturally mean that the button will be wider on a iPhone 6 Plus, since the screen is bigger and the button will have to be wider to be 25 points of the edges.
It's all a trade off, but if the button contents are simple it's easy to do in code and it reduces future maintenance. If you use images you need to follow the standard #1x, #2x, #3x approach so you'll have multiple copies of the same images at different sizes. You won't really notice a performance difference in either case, the images are generally cached for you (if you load then using the name) and they aren't large images.
Loading assets into a UIButton for different states has more impact on memory than changing the Fonts color. The impact is so small though, that it is unlikely you will ever notice.
So I'd say this one is up to you. Keep in mind though that you sacrifice a lot of flexibility by using static images.
For your second question:
Yes it is possible to vary the size of UI Elements depending on the screen Size / iPhone / iPad Version.
For that have a look at Apples Autolayout.

iPhone App not showing up properly on iphone 6 simulator

My app works good on iphone 4s, 5 , 5s simulators. On iphone 6,it shows up weirdly. It does not occupy the entire screen
What could be the issues?
if you are using the Auto resizing just under stand the concept for example
assume that u have a book self , u need to layout the book in the book self so u need to do the following steps
initially arrange the book self (this is your main View).
arrange the all books in inside the book self where u need the location (this is your subview, buttons, labels, all UI Elements).
u keep to follow the above two steps in always. got it
need reference follow the apple tutorial
this tutorial may also help u
The black view is an added view? If the goal is just to set the background color, better to just set the color of the root view.
If you're not using autoLayout (and I don't reccomend it, it's more trouble than it's worth in most cases) one simple to handle different screeen sizes is programatically.
Everything in the view in Interface Builder needs to be an outlet.
in -viewDidLoad, set the center of each view. For example, to center the mobile number text: [self.enterYourMobileNumberLabel setCenter: CGMakePoint(self.view.center.x, self.enterYourMobileNumberLabel.center.y)]
You could also set the frame for more percise handling, etc., using margin constants. Frames are often more code and more cumbersome, but AutoLayout is a nightmare.
Resolved the issue. Thanks for your valuable responses users.It has got nothing to do with Autolayout or autoresizing.
Just go to images.xcassets, right clicking in the navigator area, add launchImage. Then select your project (or target), go to general-->App Icons and Launch images and set Launch Images Source as Launch Image and most importantly, set Launch Screen file blank.
The app would now work well in iphone 6 simulator too.

Resources