第二天

今天是第二天回憶基礎(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];
}*/
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容