TigerCoding
TigerCoding

Reputation: 8720

Why does a UIButton have 3 different image properties?

A UIButton has 3 different image properties:

currentBackgroundImage currentImage imageView

What do each of them represent?

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIButton_Class/UIButton/UIButton.html

Upvotes: 1

Views: 311

Answers (1)

sergio
sergio

Reputation: 69027

I would say that a UIButton has two sets of images:

  1. those assigned through: setImage:forState:

  2. those assigned through 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".)

Now, currentBackgroundImage and currentImage allow direct access to the current image (i.e., the image corresponding to the current state of the button).

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. E.g. (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;

Upvotes: 5

Related Questions