[英]Why does a UIButton have 3 different image properties?
A UIButton has 3 different image properties: UIButton具有3种不同的图像属性:
currentBackgroundImage currentImage imageView currentBackgroundImage currentImage imageView
What do each of them represent? 他们每个代表什么?
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIButton_Class/UIButton/UIButton.html http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIButton_Class/UIButton/UIButton.html
I would say that a UIButton
has two sets of images: 我会说
UIButton
有两组图像:
those assigned through: setImage:forState:
那些通过以下方式分配的:
setImage:forState:
those assigned through setBackgroundImage:forState:
通过
setBackgroundImage:forState:
分配的那些setBackgroundImage:forState:
They allow you to set foreground and background images for the allowed states to a button: UIControlStateNormal
, UIControlStateHighlighted
, UIControlStateDisabled
, UIControlStateSelected
, etc. (they are described in the doc you link to, under section "Control State".) 它们允许您将允许状态的前景图像和背景图像设置为按钮:
UIControlStateNormal
, UIControlStateHighlighted
, UIControlStateDisabled
, UIControlStateSelected
等(在您链接到的文档的“控制状态”部分下进行描述)。
Now, currentBackgroundImage
and currentImage
allow direct access to the current image (ie, the image corresponding to the current state of the button). 现在,
currentBackgroundImage
和currentImage
允许直接访问当前图像(即,与按钮的当前状态相对应的图像)。
On the other hand, imageView
allows to have access to the UIImageView
object underlying the button image, so that you can set its properties, if needed. 另一方面,
imageView
允许访问按钮图像下面的UIImageView
对象,以便您可以根据需要设置其属性。 Eg (from the doc you link): 例如(从您链接的文档中):
Although this property is read-only, its own properties are read/write.
尽管此属性是只读的,但它自己的属性是读/写。 Use these properties to configure the appearance and behavior of the button's view.
使用这些属性可以配置按钮视图的外观和行为。 For example:
例如:
UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect]; button.imageView.exclusiveTouch = YES;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.