0

I know how to set contentmode of button's imageview to aspect to fit, but I'm using button's backgroundImage.

How to access and set it as I want?

Filburt
  • 17,626
  • 12
  • 64
  • 115
  • you can use another UIImageView for showing image inside UIButton either by adding subview or by adding to storyboard and below the UIButton and add constraints so it will fix with the UIButton – Varun Naharia Sep 07 '15 at 09:06

1 Answers1

0

I think the only way is to add a UIImageView in button as subview. and set it's content mode. make the frame of the uiimageview same as button's frame.

or you can use autolayout to pin all uiimageview's edge to it's superview and add it as subview.

 UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
 [imageView setFrame:btn.frame];
 [imageView setContentMode:UIViewContentModeScaleToFill];
 [btn addSubView:imageView];
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88