84669 人學習
152542 人學習
20005 人學習
5487 人學習
7821 人學習
359900 人學習
3350 人學習
180660 人學習
48569 人學習
18603 人學習
40936 人學習
1549 人學習
1183 人學習
32909 人學習
我在网上搜了一下,基本都是说
setBackgroundImage,image会随着button的大小而改变,图片自动会拉伸来适应button的大小,这个时候任然可以设置button的title,image不会挡住title;
相反的的setImage,图片不会进行拉伸,原比例的显示在button上,此时再设置title,title将无法显示,我想问的是这些区别的原始出处是哪里? 我在uibutton的 官方的 class reference里都没找到
走同样的路,发现不同的人生
(1) background image, title, image(前景圖片) 是有z-index的, 在UIButton建立的時候就已經定好了,所以setBackgroundImage 和 setImage的效果是不一樣的。 (2) 關於UIButton裡的Image和title, apple 官方文件解釋的還是很詳細的:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/ doc/uid/TP40006815-CH3-SW31(2.1) "Figure 1Providing a title and image for a button" 上面Content部分解釋了title和image分別是UILabel和UIImageView(2.2) “Conguring Edge 有三個屬性” contentEdgeInsets, titleEdgeInsets, imageEdgeInsets, 調整值可以實現左文字右圖片。 (2.3) UIImageView 關於用resizableImageWithCapInsets:resizingMode: 如何調整大小,也作了詳細說明:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/index.htmlios/ apple_ref/occ/cl/UIImageView(2.4) image的內容展現模式由UIImageView的contentMode決定;顯然background image使用了預設模式UIViewContentModeScaleToFill。 請參考看實例:http://blog.csdn.net/iunion/article/details/7494511
請參考以下程式碼,在setImage之前先修改contentMode,看看會有什麼不同:
//模式1. self.btnTestImage.imageView.contentMode = UIViewContentModeScaleAspectFit; //模式2. //self.btnTestImage.imageView.contentMode=UIViewContentModeScaleAspectFill; [self.btnTestImage setImage:imgW200 forState:UIControlStateNormal];
(3) 圖片最好還是事先處理到合適的小尺寸,沒有你現在遇到的困惑。你現在用大圖片,就要寫一堆圖片裁減的程式碼。給你一個UIImage category的連結作參考:http://blog.sina.com.cn/s/blog_6123f9650100p88p.html
(1) background image, title, image(前景圖片) 是有z-index的, 在UIButton建立的時候就已經定好了,所以setBackgroundImage 和 setImage的效果是不一樣的。
(2) 關於UIButton裡的Image和title, apple 官方文件解釋的還是很詳細的:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/ doc/uid/TP40006815-CH3-SW31
(2.1) "Figure 1Providing a title and image for a button" 上面Content部分解釋了title和image分別是UILabel和UIImageView
(2.2) “Conguring Edge 有三個屬性” contentEdgeInsets, titleEdgeInsets, imageEdgeInsets, 調整值可以實現左文字右圖片。
(2.3) UIImageView 關於用resizableImageWithCapInsets:resizingMode: 如何調整大小,也作了詳細說明:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/index.htmlios/ apple_ref/occ/cl/UIImageView
(2.4) image的內容展現模式由UIImageView的contentMode決定;
顯然background image使用了預設模式UIViewContentModeScaleToFill。
請參考看實例:
http://blog.csdn.net/iunion/article/details/7494511
請參考以下程式碼,在setImage之前先修改contentMode,看看會有什麼不同:
(3) 圖片最好還是事先處理到合適的小尺寸,沒有你現在遇到的困惑。你現在用大圖片,就要寫一堆圖片裁減的程式碼。給你一個UIImage category的連結作參考:
http://blog.sina.com.cn/s/blog_6123f9650100p88p.html