IOS Custom UIButton

Source: Internet
Author: User

There is a click button in the work to update the button above the requirements of the case, with the custom button can be very simple implementation of this requirement

Start by writing a custom button

CustomButton.h

#import <UIKit/UIKit.h>typedef ns_enum (Nsuinteger, custombuttonstatus) {    0 ,     1 }; @interface Custombutton:uibutton@property (nonatomic) custombuttonstatus buttonstatus; @end

Custombutton.m

#import "CustomButton.h"@implementationCustomButton- (void) Setbuttonstatus: (custombuttonstatus) buttonstatus{nsstring*title; if(Custombuttonstatusnormal = =buttonstatus) {Title=@" Oh, yes."; } Else if(Custombuttonstatusreverse = =buttonstatus) {Title=@" Oh, oh, oh.";    } [self settitle:title forstate:uicontrolstatenormal]; _buttonstatus=Buttonstatus;}@end

Call

#import "ViewControllerTest.h"#import "CustomButton.h"@interfaceviewcontrollertest () {CustomButton*button;}@end@implementationviewcontrollertest- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Whitecolor]; Button=[CustomButton Buttonwithtype:uibuttontypecustom];    [Button Setbuttonstatus:custombuttonstatusnormal]; [Button Setframe:cgrectmake ( $, the, the, the)];    [Button addtarget:self action: @selector (Custombuttonclick:) forcontrolevents:uicontroleventtouchupinside];    [Button Setbackgroundcolor:[uicolor Redcolor]; [Self.view Addsubview:button];}-(void) custombuttonclick:sender{Button.buttonstatus= !Button.buttonstatus;}

IOS Custom UIButton

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.