其他分享
首页 > 其他分享> > IOS14.3开发之使用纯代码创建UIButton以及弹框的使用

IOS14.3开发之使用纯代码创建UIButton以及弹框的使用

作者:互联网

IOS14.3开发之使用纯代码创建UIButton以及弹框的使用

在这里插入图片描述
源码在这

//
//  ViewController.m
//  testDemo1
//
//  Created by 鲁军 on 2021/3/4.
//

#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn  = [UIButton buttonWithType:UIButtonTypeInfoDark];
    btn.frame = CGRectMake(130, 80, 40, 40);
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn2.frame = CGRectMake(80, 180, 150, 44);
    btn2.backgroundColor = [UIColor purpleColor];
    btn2.tintColor = [UIColor yellowColor];
    [btn2 setTitle:@"Tap Me" forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIButton *btn3= [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn3.backgroundColor = [UIColor brownColor];
    btn3.tintColor  = [UIColor whiteColor];
    [btn3 setTitle:@"Tap Me" forState:UIControlStateNormal];
    btn3.frame = CGRectMake(80, 280, 150, 44);
    btn3.layer.masksToBounds = YES;
    btn3.layer.cornerRadius = 10;
    btn3.layer.borderWidth=4;
    btn3.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [self.view addSubview:btn];
    [self.view addSubview:btn2];
    [self.view addSubview:btn3];
}
-(void)btnClick:(UIButton *)sender{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"information" message:@"UIButton Event" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:OKAction];
    [self presentViewController:alert animated:YES completion:nil];
}
@end

标签:ViewController,self,弹框,UIColor,IOS14.3,UIButton,btn2,btn3
来源: https://blog.csdn.net/A1521315qwss/article/details/114417294