button 图片保真

设置图片显示的状态,有这么几个属性.根据情况具体使用

typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};

如果我们使用的是使用的 imageView ,

imageView.contentMode = UIViewContentModeScaleAspectFill;

这样就能达到我们的效果,但是如果使用的是button.要满足三个条件

  1. 用 button.imageView.contentMode 而不是 button.contentMode

  2. 打开 clipsToBounds 属性. 设置为 YES

  3. 设置的是 image 而不是 backGroundImage ,设置 backGroundImage 没有效果.

button.imageView.contentMode = UIViewContentModeScaleAspectFill;

button.clipsToBounds = YES;

[button sd_setImageWithURL:[NSURL URLWithString:imag1] forState:UIControlStateNormal];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、初始化方法 1、- initWithFrame: UIView *view = [[UIView alloc]...
    默默_David阅读 2,571评论 1 3
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,147评论 5 13
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,554评论 1 14
  • SomeSEL 数组的方法 初始化方法 用stroyboard和xib里初始化会调用initWithCoder里面...
    蒋昉霖阅读 222评论 0 2
  • 1.形成良性的自我激励(Self-Sufficiency in Growth Signals), 2.不良应激的应...
    秦健勇阅读 220评论 0 1