UIButton image resize/scale to fit

一世执手 提交于 2019-12-04 17:38:56

Try setBackgroundImage instead of setImage, and do nothing to the image. (resize or setContentMode) Hope this helps

UIImage *thubNailImage=[UIImage imageNamed:@"thumImage"];
[button.imageView setContentMode:UIViewContentModeScaleAspectFill];
CGSize imageSize=thubNailImage.size;
[button setImage:thubNailImage forState:UIControlStateNormal];
button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, 0);

If you don't want to show the title then remove the last line ( button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, 0);)

I think this is help for someone. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!