How to set contentMode of button's backgroundImagView as UIViewContentModeScaleToFill?

152 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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];