Resizing Image in Xcode? - ios

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.

Related

How to install image for UIBarButtonItem of standard size?

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.

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.

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.

Left constraints in Xcode 7

So I'm doing a tut on iOS 9 development with Xcode 7, and in the example I'm currently doing the instruction is adding constraints using ctrl+drag and clicking on a second image. Now my issues isn't with that process, my issue is when the video asks me to set left constraints (the right image attached) I don't have that option (the left side of the image attached). I tried "leading" just to see what it would do and it did not achieve desired results. I'm guessing that this is changed in Xcode 7 and there is a new method of achieving this result?
Any help is appreciated, thanks!
EDIT: To update my question as per a suggestion below, here's what's happening. I have a background image view. When I am lining up image buttons along the background image, the first one is just fine, once I select the second one, and add the leading constraint, then lock in the width and height in the main constraints - it flies off the page somewhere. The background image is horizontally and vertically aligned to the container, and the main reason I'm doing this is I have "landscape mode" pulled up in a main preview window and I want to make sure that everything is looking good in that mode.
I have tried starting a new project all together and I get the same result. Again the tutorial I'm following was using Xcode 7 beta, so not sure if that has something to do with it. I'd like to lock in on the problem instead of skipping over it in case I run into this in the future.
Thanks!
Try using the main constraints menu at the button of Xcode.
See below screenshot: click the element you want to add a constraints to and it will give you the options you need.
Cheers,
Tal

How to reslice an image in Xcode?

I am often a bit silly when I try to slice resizable images, and end up in this situation:
As you can see, I've done a 9-slice on the top image, and a 3-slice on the bottom. And yet, Xcode doesn't let me back out of this. My option seems to be deleting and then re-adding the image. But is there a way do re-specify slicing within Xcode?
While in slicing view, select the image you are want to reset (click on its title) and open the attributes inspector in the right sidebar (⌥⌘4). Under "Slicing" you can change slicing parameters, and even disable it.

Resources