iOS開發中UIButton的setImage和setBackgroundImage用法區別

- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;                      // default is nil. should be same size if different for different states

該方法不會拉伸圖片,保持圖片的原始比例顯示在Button中。如果繼續設置title屬性則無法顯示。



- (void)setBackgroundImage:(nullable UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil


該方法會拉伸圖片,平鋪在Button中,不會影響繼續在Button中設置title等屬性。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章