Image size shown big in toolbar - ios

I have set 3 images on a toolbar. It looks like so...
Here I added a toolbar, added barbutton items and set images to those buttons. The image type is 1x,2x,3x format and is rendered asa default image.
But the images shown above are shown large while it should have been small given like so...
What have I done wrong..?
EDIT 1: Screenshot of UI layout

Your image resolution must be like below
Tool bar structure
Use barbutton not button
I tested it, its work properly
Output

Wherever you define you images you need to use this line:
let image = yourImage
image.size = CGSize(width: 40, height: 40)
If your image is in the storyboard click on the image and then go to the measurement attribute and change the values there.
Explanation: Our app doesn't know what size we want our image to be so it (by default) sets the image size from the image so we need to define our own size.

This because of your images too big. Downscale your image about twice.
Good 1x size is 25x25; 2x - 50x50; 3x - 150x150. You could not put 1x images in your asset.

Related

#1x size of image assets in iOS

When adding images to an iOS project, what size should the 1x image be?
For example:
If I have 2 UIImageView with the same image with a size of 50x50pt and 30x30pt. Can I make one image asset for the both (and which size should this be) or should I make 2 assets ie. image30x30.png and image50x50.png?
This of course extends to images that have a dynamic size (for example 50% of the screen width), which size should they be?
You have 2 options:
Use 1 image and just resize UIImageView
Yes, you should use 2 different assets if 1. won't work for you
When you want to resize an image you must remember 2 things:
you must maintain the h/w ratio of that image.
you must resize to smaller from it's original size otherwise the resized image will look blur .
So, according to your (50x50pt and 30x30pt)images size the best option is to maintain 1 image and it size must be 50x50pt
i) resize this image smaller into 30x30pt
ii) you should not consider image ratio as both image maintain same ratio.(50/50=1 and 30/30 =1)
You have to use 2 different image assets for your UIImageView.

Should I use xcassets or just change the size of one image to develop on multiple devices in iOS?

I want to show a placeholder image on my UICollectionView until the cell fetches an image from my server. However, I wonder whether I should prepare three different images in advance for the case 1x, 2x, and 3x in Images.xcassests, or just prepare one SVG file and manipulate its size once the image is loaded within code.
Specifically, if you take the first approach your procedure is something like this:
let imageView = UIImageView(image: UIImage(named: "PlaceholderImageInXcassets")) // frame is set to the size of the image automatically
self.view.addSubview(imageView)
And this is the second approach:
let imageView = UIImageView(image: UIImage(named: "PlaceholderImage"))
imageView.frame = CGRectMake(0, 0, 128, 128) // alter the frame depending on the size of the device
self.view.addSubview(imageView)
So here is my question:
Is there any difference at the output of the image displayed?
If you use SVG file you don't need to worry about seeing the dirty image even after expanding the size, right?
Which is the better in performance or a recommended way?
Using Image assets for image loading for various device is more performance effective and faster and is encouraged by apple themselves.

Image gets distorted when used as button image

I created an image which is intended to be used as background image of UIButton. This is what I get:
The image looks great in Photoshop, but when used in iOS application as a button image it looks distorted(the lines are not strait and definitely not as smooth as in the original). How can I avoid this effect?
EDIT:// Preview window
Are you sure that aspect ratios of button and image are the same?
Another thing - use appropriate image size for button image, e.g button view is 30px high, then you need add 30px(#1x), 60px(#2x) and 90px(#3x) images. If you just add an image with 1000px it won't look good, take more disk space and reduce performance.

Swift: Edit image taken from camera to fill a UIImageView

I have used a UIImageView that takes its image from the default camera app using UIPicker. But the image I am getting is too small to fit into the image view and if I use:
imageView.contentMode = UIViewContentMode.ScaleToFill
While this indeed scales to fit the image view the picture looks like it has been mashed up and not particularly good. I was wondering if it was possible to scale the image up in such a way that the quality of the image does not get bad.
I am using Swift 1.2 and thanks for any help! :D
It will work with:
myImageView.contentMode = .ScaleAspectFit
Camera images are usually bigger than a UIImageView on a device. To shrink them quickly to a visible size, the best way is to set the .contentView property of UIImageView to .ScaleAspectFit.
try using UIViewContentMode.ScaleAspectFill
that fills the imageview by keeping the original aspect ratio. but that also means that parts of the image could be outside of the bounds of the imageview and therefore not visible.
If you use a uiImagePickerController, you can adjust the quality with the property videoQuality : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class/#//apple_ref/occ/instp/UIImagePickerController/videoQuality
Juste set the quality type as TypeHigh

How to use a retina image for Trigger.io setTitleImage in native topbar

I am trying to use the setTitleImage feature of trigger.io. I have an image that I saved #2x its original dimensions and am referencing it like so in the my main.js file:
forge.topbar.setTitleImage("img/logo#2x.png");
However, the image does not resize properly and I end up with a huge title image. Please advise on how to set a retina friendly title image in the native topbar.
The image you set will be scaled to the exact height of the topbar if it is larger than it, you probably just need to include some transparent padding at the top and bottom of your image to scale it to the right size.

Resources