Button setImage设置的图片默认是会拉伸缩放的,如果我想要Aspect Fit的效果,要如何做呢?一开始我想到了用contentMode属性,很可惜不起作用。后来我发现button有一个imageView属性,设置它的contentMode就OK了。代码如下:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.imageView.contentMode = UIViewContentModeScaleAspectFit;

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2021-11-02
  • 2021-09-29
相关资源
相似解决方案