【发布时间】:2012-01-10 19:50:04
【问题描述】:
一个 UIButton 有 3 个不同的图像属性:
当前背景图像 当前图像 图像视图
它们各自代表什么?
【问题讨论】:
标签: iphone ios ipad cocoa-touch uibutton
一个 UIButton 有 3 个不同的图像属性:
当前背景图像 当前图像 图像视图
它们各自代表什么?
【问题讨论】:
标签: iphone ios ipad cocoa-touch uibutton
我会说UIButton 有两组图像:
分配者:setImage:forState:
那些通过setBackgroundImage:forState:分配的人
它们允许您将允许状态的前景和背景图像设置为按钮:UIControlStateNormal、UIControlStateHighlighted、UIControlStateDisabled、UIControlStateSelected 等(它们在您链接到的文档中进行了描述,在“控制状态”部分。)
现在,currentBackgroundImage 和 currentImage 允许直接访问当前图像(即与按钮当前状态对应的图像)。
另一方面,imageView 允许访问按钮图像下的UIImageView 对象,以便您可以在需要时设置其属性。例如。 (来自您链接的文档):
虽然这个属性是只读的,但它自己的属性是读/写的。使用这些属性来配置按钮视图的外观和行为。例如:
UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect]; button.imageView.exclusiveTouch = YES;
【讨论】:
imageView 让您可以访问底层的UIImageView。我在回答中写了UIView,只是因为我认为需要修改UIView 属性更常见(除非您尝试使用动画按钮,例如)。我将编辑我的答案以更准确...