美文网首页
iOS基础控件button label text

iOS基础控件button label text

作者: 七岁小猫 | 来源:发表于2019-05-17 17:23 被阅读0次

    自身Android6年开发经验,原生和混合都接触过,也有iOS App Store上架经验,只不过用的是混合框架,从今天开始自学iOS开发,想体验一下原生开发的感觉,特意写下学习笔记,微信都已经改名,立下flag。

    image image

    2019-05-17 iOS学习笔记

    按照视频教程今天主要学习了iOS基础控件,包含button label text。

    iOS开发使用的工具是xcode,控件主要有拖拽和代码动态创建两种方法,因为自身是Android出身,所以习惯拖拽控件。(其实是动态创建太难了,对于刚入门的我真的有点难度)

    image

    主要有两个功能:

    1、计算器、QQ登录界面

    - (IBAction)compute {
        NSString *num1 =  self.text1.text;
        NSString *num2 =  self.text2.text;
        int result = num1.intValue + num2.intValue;
        
        self.label.text = [NSString stringWithFormat:@"%d",result];
        
        //收回键盘
    //    [self.text1 resignFirstResponder];
    //    [self.text2 resignFirstResponder];
        
        //让控制器管理的view停止编辑
        [self.view endEditing:true];
    }
    

    学习点:String转int,label赋值,收回键盘,text输入限制。

    - (IBAction)login {
        NSLog(@"qq----%@",self.qq.text);
        NSLog(@"psw----%@",self.psw.text);
        
        NSString *str = [NSString stringWithFormat:@"qq----%@\npsw----%@",self.qq.text,self.psw.text];
        
        //初始化提示框;
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:  UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件;
            NSLog(@"点击了确定");
        }]];
        
        //弹出提示框;
        [self presentViewController:alert animated:true completion:nil];
        
        [self.view endEditing:YES];
    }
    

    学习点:设置清除text的CleanButton,alert提示框。

    2、控制图片移动及改变大小

    - (IBAction)up {
        NSLog(@"上");
        //获取图片原始frame
        CGRect frame =  self.img.frame;
        frame.origin.y -= 10;
        self.img.frame = frame;
    }
    
    - (IBAction)left {
        NSLog(@"左");
        //获取图片原始frame
        CGRect frame =  self.img.frame;
        frame.origin.x -= 10;
        self.img.frame = frame;
    }
    
    - (IBAction)right {
        NSLog(@"右");
        //获取图片原始frame
        CGRect frame =  self.img.frame;
        frame.origin.x += 10;
        self.img.frame = frame;
    }
    
    - (IBAction)down {
        NSLog(@"下");
        //获取图片原始frame
        CGRect frame =  self.img.frame;
        frame.origin.y += 10;
        self.img.frame = frame;
    }
    
    - (IBAction)big {
        NSLog(@"大");
        //获取图片原始bounds
        CGRect bounds =  self.img.bounds;
        bounds.size.height +=10;
        bounds.size.width +=10;
        self.img.bounds = bounds;
    }
    
    - (IBAction)small {
        NSLog(@"小");
        //获取图片原始bounds
        CGRect bounds =  self.img.bounds;
        bounds.size.height -=10;
        bounds.size.width -=10;
        self.img.bounds = bounds;
    }
    @end
    

    3、跳转页面

    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"ViewFirst" bundle: [NSBundle mainBundle]];
    
    ViewFirst *v = [story instantiateViewControllerWithIdentifier:@"MyView"];
    
    [self presentViewController: v animated:YES completion:nil];
    
    

    相关文章

      网友评论

          本文标题:iOS基础控件button label text

          本文链接:https://www.haomeiwen.com/subject/imgoaqtx.html