标签:ViewController self 弹框 UIColor IOS14.3 UIButton btn2 btn3
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
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。