第二天

今天是第二天回忆基础代码了,今天回忆的比较多,整理了一下却发现总共也就三种,接下来是第一篇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 *)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(@"跳转");
    [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.
}
*/

//如何跳转回去
- (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(@"跳转");
    NextViewController *next = [[NextViewController alloc]init];
    [self presentViewController:next animated:YES completion:nil];

}
/*- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"Hello,word");
    NextViewController *next = [[NextViewController alloc]init];
    [self presentViewController:next animated:YES completion:nil];
}*/

你可能感兴趣的:(第二天)