0

I have set 3 images on a toolbar. It looks like so...

enter image description here

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..?

enter image description here

EDIT 1: Screenshot of UI layout

enter image description here

3 Answers3

1

Your image resolution must be like below

enter image description here

Tool bar structure

enter image description here

Use barbutton not button

enter image description here


I tested it, its work properly

Output

enter image description here

dahiya_boy
  • 9,298
  • 1
  • 30
  • 51
  • ok @dahiya_boy...so u r saying it is the image resolution that must be changed..? –  Mar 18 '19 at 10:39
  • @asd2 Yeah and better in nav bar and tool bar you use barbutton. It can work like `UIImageView/UIButton/UILabel`. You img resolution will be 20px, 40px, 60 px (for now) – dahiya_boy Mar 18 '19 at 10:40
0

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.

Oscar
  • 404
  • 7
  • 19
  • but when I try to change the button sizes in storyboard, it doesn't allow me to change.. –  Mar 18 '19 at 08:56
0

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.