How to install image for UIBarButtonItem of standard size? - ios

When I try to add my image to a UIBarButtonItem, it changes its size. Setting the width for the UIBarButtonItem does not help fix the situation.
I would like to add one large image that would suit any device.
When I add an image of 500*500px, the button becomes very wide.
When I add a button of 20*20px, it is so small that I can barely see a point on the panel.
I found several solutions here, but they are all quite old and work when adding a button via code.
Is it possible to do this through Interface Builder?
If not, at least a solution for Swift 4.
In general, it looks very strange and illogical, if it is not possible to add an image to a UIBarButtonItem through the builder interface, so that they remain normal sizes. No wonder this opportunity is there.

Download your images in 3 formats: 25px, 50px and 75px and put behind the image name #1x, #2x, #3x then you can just use storyboard to place them.

Related

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.

Resizing Image in Xcode?

Is there any way I can resize an image that I copy into my project, according the the size I need in pixels for example maybe I want to reduce the height and width by 100px then add it to my imageView or any other object. are there any tools that Xcode provide within the Xcode. I want to do it using interface without any programming so is there any way?
The simple answer would be "NO".
I do not aware of any way to use Xcode resizing images.
The easiest method for me is to right click on any image and select "Open with External Editor". Preview should be opened and the app is quite simple to use.
Assuming that you are referring to the layout in storyboard/IB.
To get the native size of the image just select the image and press Command + = on the keyboard. the to re-size it proportionally select the corner and hold down the shift key when you re-size it.

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.

IOS UITabbarController set Image is not possible

Hello my Guys i have some Problems to set the image in the UITabbarController. I use the Interfacebuilder to do that. But when I start the Simulator the tabs don't even images. It would be very nice when you can help me.
it's better to get 10*10 size png images, and add it to your tab item, and then you will come to know what size you can use.

LaunchScreen.xib not displaying my custom font

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.

Resources