美文网首页
button 图片保真

button 图片保真

作者: 学而不思则罔思而不学则殆 | 来源:发表于2017-07-19 14:10 被阅读19次

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

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

相关文章

网友评论

      本文标题:button 图片保真

      本文链接:https://www.haomeiwen.com/subject/jaslkxtx.html