0

I have @1x, @2x, and @3x image, but when I change the image of the button, the image does not fill the size of the button, instead it's really small. Why is this happening? How do I fix it? Any help is appreciated.

self.reg.setImage(UIImage(named: "regButton.png"), forState: UIControlState.Normal)

    self.in.setImage(UIImage(named: "inStart.png"), forState: UIControlState.Normal)
Shripada
  • 6,296
  • 1
  • 30
  • 30

3 Answers3

1

try the button property as like

button.contentMode = .ScaleToFill
button.contentHorizontalAlignment = .Fill
button.contentVerticalAlignment = .Fill

else try

self.reg.setImage(UIImage(named: "regButton"), forState: UIControlState.Normal)

inthis place use

self.reg.setBackgroundImage(UIImage(named: "regButton"), forState: UIControlState.Normal)

else another option

self.reg.imageView().contentMode = .ScaleAspectFit
self.reg.setImage(UIImage(named: "regButton"), forState: .Normal)
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

If you are using imageassets. No need to use the image extention. Simple add the image name. At run time as per the device it will pick the image as per the device resolution.

Edited code:

self.reg.setImage(UIImage(named: "regButton"), forState: UIControlState.Normal)

self.in.setImage(UIImage(named: "inStart"), forState: UIControlState.Normal)

For more info: https://stackoverflow.com/a/26085718/3051458

Community
  • 1
  • 1
Ramesh_T
  • 1,251
  • 8
  • 19
0

Try

self.in.imageView?.contentMode = .ScaleAspectFit
self.reg.imageView?.contentMode = .ScaleAspectFit
Stefan
  • 5,203
  • 8
  • 27
  • 51
Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68