Custom UIButton for iOS and custom uibutton for ios

Source: Internet
Author: User

Custom UIButton for iOS and custom uibutton for ios

There is a need to click the button to update the text on the button. You can easily implement this requirement with a custom button.

First, write a Custom button.

CustomButton. h

#import <UIKit/UIKit.h>typedef NS_ENUM(NSUInteger, CustomButtonStatus){    CustomButtonStatusNormal = 0,    CustomButtonStatusReverse = 1};@interface CustomButton : UIButton@property(nonatomic) CustomButtonStatus buttonStatus;@end

 

CustomButton. m

# Import "CustomButton. h "@ implementation CustomButton-(void) setButtonStatus :( CustomButtonStatus) buttonStatus {NSString * title; if (CustomButtonStatusNormal = buttonStatus) {title = @" ah ";} else if (CustomButtonStatusReverse = buttonStatus) {title = @ "Oh oh";} [self setTitle: title forState: UIControlStateNormal]; _ buttonStatus = buttonStatus;} @ end

 

Call

#import "ViewControllerTest.h"#import "CustomButton.h"@interface ViewControllerTest () {    CustomButton *button;}@end@implementation ViewControllerTest- (void)viewDidLoad {    [super viewDidLoad];        self.view.backgroundColor = [UIColor whiteColor];        button = [CustomButton buttonWithType:UIButtonTypeCustom];    [button setButtonStatus:CustomButtonStatusNormal];    [button setFrame:CGRectMake(200, 80, 86, 42)];    [button addTarget:self action:@selector(customButtonClick:) forControlEvents:UIControlEventTouchUpInside];    [button setBackgroundColor:[UIColor redColor]];    [self.view addSubview:button];}-(void) customButtonClick: sender{    button.buttonStatus = !button.buttonStatus;}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.