button 圖片保真

設(shè)置圖片顯示的狀態(tài),有這么幾個屬性.根據(jù)情況具體使用

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;

這樣就能達(dá)到我們的效果,但是如果使用的是button.要滿足三個條件

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

  2. 打開 clipsToBounds 屬性. 設(shè)置為 YES

  3. 設(shè)置的是 image 而不是 backGroundImage ,設(shè)置 backGroundImage 沒有效果.

button.imageView.contentMode = UIViewContentModeScaleAspectFill;

button.clipsToBounds = YES;

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、初始化方法 1、- initWithFrame: UIView *view = [[UIView alloc]...
    默默_David閱讀 2,723評論 1 3
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現(xiàn)這些動畫的過程并不復(fù)雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,270評論 5 13
  • *7月8日上午 N:Block :跟一個函數(shù)塊差不多,會對里面所有的內(nèi)容的引用計數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,734評論 1 14
  • SomeSEL 數(shù)組的方法 初始化方法 用stroyboard和xib里初始化會調(diào)用initWithCoder里面...
    蔣昉霖閱讀 246評論 0 2
  • 1.形成良性的自我激勵(Self-Sufficiency in Growth Signals), 2.不良應(yīng)激的應(yīng)...
    秦健勇閱讀 271評論 0 1

友情鏈接更多精彩內(nèi)容