rfc cfcfc
rfc cfcfc

Reputation: 1

Why is the image so small?

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)

Upvotes: 0

Views: 179

Answers (3)

Avijit Nagare
Avijit Nagare

Reputation: 8802

Try

self.in.imageView?.contentMode = .ScaleAspectFit
self.reg.imageView?.contentMode = .ScaleAspectFit

Upvotes: 0

Anbu.Karthik
Anbu.Karthik

Reputation: 82756

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)

Upvotes: 1

Ramesh_T
Ramesh_T

Reputation: 1261

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

Upvotes: 0

Related Questions