怎麽獲取UIButton標題?
阿新 • • 發佈:2017-08-31
uibutton
UIButton在不同狀態(被點擊\正常狀態\不可用\ ...)標題是可以不同的
按鈕的狀態
typedef NS_OPTIONS(NSUInteger, UIControlState) { UIControlStateNormal = 0, UIControlStateHighlighted = 1 << 0, // used when UIControl isHighlighted is set UIControlStateDisabled = 1 << 1, UIControlStateSelected = 1 << 2, // flag usable by app (see below) UIControlStateFocused NS_ENUM_AVAILABLE_IOS(9_0) = 1 << 3, // Applicable only when the screen supports focus UIControlStateApplication = 0x00FF0000, // additional flags available for application use UIControlStateReserved = 0xFF000000 // flags reserved for internal framework use };
以下代碼獲取正常狀態下的標題,並賦值給別的變量
UIControlStateNormal為正常狀態
- (IBAction)buttonPressed:(UIButton *)sender { NSString *title = [sender titleForState:UIControlStateNormal]; NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.", title]; _statusLable.text = plainText; }
怎麽獲取UIButton標題?