澳门正规赌博十大网站-澳门游戏网站
做最好的网站

ReactNative学习之自定义Button

iOS 自定义UIButton,ios自定义uibutton

办事中有一个点击button更新button上文案的必要,用自定义了button能够比较轻巧的落实的这些供给

第后生可畏写个自定义的button

ReactNative学习之自定义Button。CustomButton.h

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, CustomButtonStatus){
    CustomButtonStatusNormal = 0,
    CustomButtonStatusReverse = 1
};

@interface CustomButton : UIButton

@property(nonatomic) CustomButtonStatus buttonStatus;

@end

ReactNative学习之自定义Button。 

ReactNative学习之自定义Button。CustomButton.m

#import "CustomButton.h"

@implementation CustomButton

- (void)setButtonStatus:(CustomButtonStatus)buttonStatus{
    NSString *title;
    if (CustomButtonStatusNormal == buttonStatus) {
        title = @"啊啊啊";
    } else if(CustomButtonStatusReverse == buttonStatus){
        title = @"哦哦哦";
    }
    [self setTitle:title forState:UIControlStateNormal];
    _buttonStatus = buttonStatus;

}
@end

 

调用

#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;
}

 

图片 1

 

自定义UIButton,ios自定义uibutton 工作中有三个点击button更新button上文案的急需,用自定义了button能够超级粗略的达成的那几个必要首先写个自...

职业中有一个点击button更新button上文案的需要,用自定义了button能够很粗略的落实的这几个要求

无论是Android依旧ios,Button控件都在这里八个原生开拓中皆已被卷入好了,大家得以一向动用。不过在TucsonN中并从未直接提供这种组件给大家,而是给大家提供了贰个可点击的构件:Touchable连串(如TouchableOpacity, TouchableHighlight等)。那么明天大家就伙同来学学封装归于我们温馨的Button。看一下大家的功能图

首先写个自定义的button

图片 2

CustomButton.h

CustomButton.gif

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, CustomButtonStatus){
    CustomButtonStatusNormal = 0,
    CustomButtonStatusReverse = 1
};

@interface CustomButton : UIButton

@property(nonatomic) CustomButtonStatus buttonStatus;

@end

图片 3

 

CustomButton_Android.gif

本文由澳门正规赌博十大网站发布于澳门游戏网站,转载请注明出处:ReactNative学习之自定义Button