今天是第二天回憶基礎(chǔ)代碼了,今天回憶的比較多,整理了一下卻發(fā)現(xiàn)總共也就三種,接下來是第一篇UIView(視圖)還是首先要初始化,然后大小,其次是背景顏色,最后是添加到視圖
UIView *vc =[[UIView alloc]init];
vc.frame = CGRectMake(20, 20, 100, 100);
vc.backgroundColor = [UIColor redColor];
[self.view addSubview:vc];
第二個是圖片的添加(UIImageView),回憶到這的時候什么都不記得了
UIImageView *image = [[UIImageView alloc]init
];
image.frame = CGRectMake(0, 0, 100, 100);
image.image = [UIImage imageNamed:@"屏幕快照 2018-10-31 下午7.00.40.png"];
[vc addSubview:image];
第三個也是用時最長的一個,這用了昨天回憶的UIButton(按鈕)也用了click
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc]init];
[btn setTitle:@">" forState:UIControlStateNormal];
btn.frame = CGRectMake(60, 10, 100, 100);
btn.backgroundColor = [UIColor blackColor];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(clickButton2) forControlEvents:UIControlEventTouchDown];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor greenColor];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0);
//返回上一頁面
//[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)clickButton2{
// NSLog(@"跳轉(zhuǎn)");
[self dismissViewControllerAnimated:YES completion:nil];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
//如何跳轉(zhuǎn)回去
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc]init];
[btn setTitle:@"<" forState:UIControlStateNormal];
btn.frame = CGRectMake(60, 10, 100, 100);
btn.backgroundColor = [UIColor blackColor];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(clickButton2) forControlEvents:UIControlEventTouchDown];
self.view.backgroundColor = [UIColor redColor];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)clickButton2{
// NSLog(@"跳轉(zhuǎn)");
NextViewController *next = [[NextViewController alloc]init];
[self presentViewController:next animated:YES completion:nil];
}
/*- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"Hello,word");
NextViewController *next = [[NextViewController alloc]init];
[self presentViewController:next animated:YES completion:nil];
}*/