Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/UIKit.framework |
Availability | Available in iOS 2.0 and later. |
Declared in | UIButton.h |
An instance of the UIButton
class implements a button on the touch screen. A button intercepts touch events and sends an action message to a target object when tapped. Methods for setting the target and action are inherited from UIControl
. This class provides methods for setting the title, image, and other appearance properties of a button. By using these accessors, you can specify a different appearance for each button state.
buttonType
property
titleLabel
property
reversesTitleShadowWhenHighlighted
property
– setTitle:forState:
– setTitleColor:forState:
– setTitleShadowColor:forState:
– titleColorForState:
– titleForState:
– titleShadowColorForState:
font
property Deprecated in iOS 3.0
lineBreakMode
property Deprecated in iOS 3.0
titleShadowOffset
property Deprecated in iOS 3.0
adjustsImageWhenHighlighted
property
adjustsImageWhenDisabled
property
showsTouchWhenHighlighted
property
– backgroundImageForState:
– imageForState:
– setBackgroundImage:forState:
– setImage:forState:
contentEdgeInsets
property
titleEdgeInsets
property
imageEdgeInsets
property
currentTitle
property
currentTitleColor
property
currentTitleShadowColor
property
currentImage
property
currentBackgroundImage
property
imageView
property
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
A Boolean value that determines whether the image changes when the button is disabled.
@property(nonatomic) BOOL adjustsImageWhenDisabled
If YES
, the image is drawn darker when the button is disabled. The default value is YES
.
UIButton.h
A Boolean value that determines whether the image changes when the button is highlighted.
@property(nonatomic) BOOL adjustsImageWhenHighlighted
If YES
, the image is drawn lighter when the button is highlighted. The default value is YES
.
UIButton.h
The button type. (read-only)
@property(nonatomic, readonly) UIButtonType buttonType
See UIButtonType
for the possible values.
UIButton.h
The inset or outset margins for the edges of the button content drawing rectangle.
@property(nonatomic) UIEdgeInsets contentEdgeInsets
Use this property to resize and reposition the effective drawing rectangle for the button content. The content comprises the button image and button title. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake
function to construct a value for this property. The default value is UIEdgeInsetsZero
.
UIButton.h
The current background image displayed on the button. (read-only)
@property(nonatomic, readonly, retain) UIImage *currentBackgroundImage
This value can be nil
.
UIButton.h
The current image displayed on the button. (read-only)
@property(nonatomic, readonly, retain) UIImage *currentImage
This value can be nil
.
UIButton.h
The current title that is displayed on the button. (read-only)
@property(nonatomic, readonly, retain) NSString *currentTitle
The value for this property is set automatically whenever the button state changes. The value may be nil
.
UIButton.h
The color used to display the title. (read-only)
@property(nonatomic, readonly, retain) UIColor *currentTitleColor
This value is guaranteed not to be nil
. The default value is white
.
UIButton.h
The color of the title’s shadow. (read-only)
@property(nonatomic, readonly, retain) UIColor *currentTitleShadowColor
The default value is white
.
UIButton.h
The inset or outset margins for the edges of the button image drawing rectangle.
@property(nonatomic) UIEdgeInsets imageEdgeInsets
Use this property to resize and reposition the effective drawing rectangle for the button image. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake
function to construct a value for this property. The default value is UIEdgeInsetsZero
.
UIButton.h
The button’s image view. (read-only)
@property(nonatomic,readonly,retain) UIImageView *imageView
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; |
The imageView
property returns a value even if the button has not been displayed yet. The value of the property is nil
for system buttons.
UIButton.h
A Boolean value that determines whether the title shadow changes when the button is highlighted.
@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted
If YES
, the shadow changes from engrave to emboss appearance when highlighted. The default value is NO
.
UIButton.h
A Boolean value that determines whether tapping the button causes it to glow.
@property(nonatomic) BOOL showsTouchWhenHighlighted
If YES
, the button glows when tapped; otherwise, it does not. The image and button behavior is not changed by the glow. The default value is NO
.
UIButton.h
The inset or outset margins for the edges of the button title drawing rectangle.
@property(nonatomic) UIEdgeInsets titleEdgeInsets
Use this property to resize and reposition the effective drawing rectangle for the button title. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake
function to construct a value for this property. The default value is UIEdgeInsetsZero
.
UIButton.h
A view that displays the value of the currentTitle
property for a button. (read-only)
@property(nonatomic,readonly,retain) UILabel *titleLabel
Although this property is read-only, its own properties are read/write. Use these properties to configure the appearance of the button label. For example:
UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect]; |
button.titleLabel.font = [UIFont systemFontOfSize: 12]; |
button.titleLabel.lineBreakMode = UILineBreakModeTailTruncation; |
button.titleLabel.shadowOffset = CGSizeMake (1.0, 0.0); |
The titleLabel
property returns a value even if the button has not been displayed yet. The value of the property is nil
for system buttons.
UIButton.h
Creates and returns a new button of the specified type.
+ (id)buttonWithType:(UIButtonType)buttonType
The button type. See UIButtonType
for the possible values.
A newly created button.
UIButton.h
Returns the background image used for a button state.
- (UIImage *)backgroundImageForState:(UIControlState)state
The state that uses the background image. Possible values are described in UIControlState
.
The background image used for the specified state.
UIButton.h
Returns the rectangle in which the receiver draws its background.
- (CGRect)backgroundRectForBounds:(CGRect)bounds
The bounding rectangle of the receiver.
The rectangle in which the receiver draws its background.
UIButton.h
Returns the rectangle in which the receiver draws its entire content.
- (CGRect)contentRectForBounds:(CGRect)bounds
The bounding rectangle for the receiver.
The rectangle in which the receiver draws its entire content.
The content rectangle is the area needed to display the image and title including any padding and adjustments for alignment and other settings.
UIButton.h
Returns the image used for a button state.
- (UIImage *)imageForState:(UIControlState)state
The state that uses the image. Possible values are described in UIControlState
.
The image used for the specified state.
UIButton.h
Returns the rectangle in which the receiver draws its image.
- (CGRect)imageRectForContentRect:(CGRect)contentRect
The content rectangle for the receiver.
The rectangle in which the receiver draws its image.
UIButton.h
Sets the background image to use for the specified button state.
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
The background image to use for the specified state.
The state that uses the specified image. The values are described in UIControlState
.
In general, if a property is not specified for a state, the default is to use the UIControlStateNormal
value. If the UIControlStateNormal
value is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.
UIButton.h
Sets the image to use for the specified state.
- (void)setImage:(UIImage *)image forState:(UIControlState)state
The image to use for the specified state.
The state that uses the specified title. The values are described in UIControlState
.
In general, if a property is not specified for a state, the default is to use the UIControlStateNormal
value. If the UIControlStateNormal
value is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.
UIButton.h
Sets the title to use for the specified state.
- (void)setTitle:(NSString *)title forState:(UIControlState)state
The title to use for the specified state.
The state that uses the specified title. The values are described in UIControlState
.
In general, if a property is not specified for a state, the default is to use the UIControlStateNormal
value. If the value for UIControlStateNormal
is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.
UIButton.h
Sets the color of the title to use for the specified state.
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state
The color of the title to use for the specified state.
The state that uses the specified color. The values are described in UIControlState
.
In general, if a property is not specified for a state, the default is to use the UIControlStateNormal
value. If the UIControlStateNormal
value is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.
UIButton.h
Sets the color of the title shadow to use for the specified state.
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state
The color of the title shadow to use for the specified state.
The state that uses the specified color. The values are described in UIControlState
.
In general, if a property is not specified for a state, the default is to use the UIControlStateNormal
value. If the UIControlStateNormal
value is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.
UIButton.h
Returns the title color used for a state.
- (UIColor *)titleColorForState:(UIControlState)state
The state that uses the title color. Possible values are described in UIControlState
.
The color of the title for the specified state.
UIButton.h
Returns the title used for a state.
- (NSString *)titleForState:(UIControlState)state
The state that uses the title. Possible values are described in UIControlState
.
The title for the specified state.
UIButton.h
Returns the rectangle in which the receiver draws its title.
- (CGRect)titleRectForContentRect:(CGRect)contentRect
The content rectangle for the receiver.
The rectangle in which the receiver draws its title.
UIButton.h
Returns the shadow color of the title used for a state.
- (UIColor *)titleShadowColorForState:(UIControlState)state
The state that uses the title shadow color. Possible values are described in UIControlState
.
The color of the title’s shadow for the specified state.
UIButton.h
Specifies the style of a button.
typedef enum { UIButtonTypeCustom = 0, UIButtonTypeRoundedRect, UIButtonTypeDetailDisclosure, UIButtonTypeInfoLight, UIButtonTypeInfoDark, UIButtonTypeContactAdd, } UIButtonType;
UIButtonTypeCustom
No button style.
Available in iOS 2.0 and later.
Declared in UIButton.h
.
UIButtonTypeRoundedRect
A rounded-rectangle style button.
Available in iOS 2.0 and later.
Declared in UIButton.h
.
UIButtonTypeDetailDisclosure
A detail disclosure button.
Available in iOS 2.0 and later.
Declared in UIButton.h
.
UIButtonTypeInfoLight
An information button that has a light background.
Available in iOS 2.0 and later.
Declared in UIButton.h
.
UIButtonTypeInfoDark
An information button that has a dark background.
Available in iOS 2.0 and later.
Declared in UIButton.h
.
UIButtonTypeContactAdd
A contact add button.
Available in iOS 2.0 and later.
Declared in UIButton.h
.
UIButton.h
Last updated: 2009-09-09