The effect is as follows:
ViewController.h
1 #import <UIKit/UIKit.h>23@interface viewcontroller: Uiviewcontroller4 @property (Strong, Nonatomic) UIButton *btnstate; 5 6 @end
Viewcontroller.m
1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 5- (void) Disablestateswitch: (Uiswitch *) sender;6 @end7 8 @implementationViewcontroller9 Ten- (void) Viewdidload { One [Super Viewdidload]; ASelf.view.backgroundColor =[Uicolor Whitecolor]; -Self.navigationItem.title =@"change the text of the button after clicking the button"; -Uiswitch *swtdisablestate =[[Uiswitch alloc] init]; theSwtdisablestate.on =YES; - [swtdisablestate addtarget:self Action: @selector (Disablestateswitch:) forControlEvents: Uicontroleventvaluechanged]; -Uibarbuttonitem *barbtndisablestate =[[Uibarbuttonitem alloc] initwithcustomview:swtdisablestate]; - [self settoolbaritems:@[barbtndisablestate] animated:yes]; + -_btnstate =[UIButton Buttonwithtype:uibuttontypecustom]; +_btnstate.frame = CGRectMake (0,0, $, -); A_btnstate.center =Self.view.center; at_btnstate.backgroundcolor = [Uicolor colorwithred:0.513Green0.894Blue1.000Alpha1.000]; -_btnstate.layer.maskstobounds =YES; -_btnstate.layer.cornerradius =10.0; -_btnstate.layer.bordercolor = [Uicolor colorwithred:1.000Green0.572Blue0.894Alpha1.000]. Cgcolor; -_btnstate.layer.borderwidth =2.0; - //Set Button caption font and shadow color in_btnstate.titlelabel.font = [Uifont boldsystemfontofsize: A]; -_btnstate.titlelabel.shadowoffset = Cgsizemake (2.0,2.0); to //set display characteristics in normal state +[_btnstate Settitle:@"Point Me"Forstate:uicontrolstatenormal]; - [_btnstate Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; the [_btnstate Settitleshadowcolor:[uicolor Graycolor] forstate:uicontrolstatenormal]; * //when the button is touched, the display feature in the highlighted State $[_btnstate Settitle:@"changed the way"forstate:uicontrolstatehighlighted];Panax Notoginseng [_btnstate Settitlecolor:[uicolor Browncolor] forstate:uicontrolstatehighlighted]; - [_btnstate Settitleshadowcolor:[uicolor Whitecolor] forstate:uicontrolstatehighlighted]; the //set the display characteristics of the button inactive (invalid) state +[_btnstate Settitle:@"Disable the button."forstate:uicontrolstatedisabled]; A [_btnstate Settitlecolor:[uicolor Graycolor] forstate:uicontrolstatedisabled]; the [_btnstate Settitleshadowcolor:[uicolor Blackcolor] forstate:uicontrolstatedisabled]; + [Self.view addsubview:_btnstate]; - } $ $- (void) didreceivememorywarning { - [Super didreceivememorywarning]; - //Dispose of any resources the can be recreated. the } - Wuyi- (void) Viewwillappear: (BOOL) Animated { the [Super viewwillappear:animated]; - [Self.navigationcontroller setnavigationbarhidden:no animated:animated]; Wu [Self.navigationcontroller settoolbarhidden:no animated:animated]; - } About $- (void) Disablestateswitch: (Uiswitch *) Sender { -_btnstate.enabled =Sender.on; - } - A @end
AppDelegate.h
1 #import <UIKit/UIKit.h>23@interface Appdelegate:uiresponder < Uiapplicationdelegate>4 @property (Strong, Nonatomic) UIWindow *window; 5 @property (Strong, Nonatomic) Uinavigationcontroller *Navigationcontroller; 6 7 @end
Appdelegate.m
1 #import "AppDelegate.h"2 #import "ViewController.h"3 4 @interfaceappdelegate ()5 @end6 7 @implementationappdelegate8 9-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Ten_window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; OneViewcontroller *viewcontroller =[[Viewcontroller alloc] init]; A_navigationcontroller =[[Uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; -_window.rootviewcontroller =_navigationcontroller; - [_window Addsubview:_navigationcontroller.view]; the [_window makekeyandvisible]; - returnYES; - } - +- (void) Applicationwillresignactive: (UIApplication *) Application { - } + A- (void) Applicationdidenterbackground: (UIApplication *) Application { at } - -- (void) Applicationwillenterforeground: (UIApplication *) Application { - } - -- (void) Applicationdidbecomeactive: (UIApplication *) Application { in } - to- (void) Applicationwillterminate: (UIApplication *) Application { + } - the @end
053 Click button to change the text of the button