zoukankan      html  css  js  c++  java
  • UI学习笔记---第一天

    一.iOS概述 

    iOS是Apple公司的移动操作系统,主要⽤用于iPhone、iPad、iPad Mini、iPod Touch等移动产品。

    借助iOS,我们可以开发视频类、美图类、新闻类、⾳乐类、团购类、电商类、阅读类、出⾏行类、⽣活服务类、游戏类等应⽤用程序。

    除此之外,iOS还可以与外部设备通信,开发出更多改变⽣活的产品,⽐比 如:智能家居(iOS App控制电视、空调等)、健⾝产品(将人体健康 状况通过App直观的展现出来)等。

    二.UI概述

    UI(User Interface):⽤户界面,⽤户能看到的各种各样的⻚面元素。

    iOS App = 各种各样的UI控件 + 业务逻辑和算法

    想要开发出⼀一款精美的应⽤程序,需要熟练掌握各种UI控件的用法。

    三.UIWindow

    window是窗口,每个app都需要借助window将内容展现给用户看

    在iOS中,使用UIWindow类来表示窗口,通常一个应用程序只创建一个UIWindow对象

    因为window的主要作用是呈现内容给用户,因此我们不会对window做太多操作

    四.UIView

    view(视图):代表屏幕上的一个矩形区域,iOS中用UIView来表示视图

    不同的控件代表不同类型的view

    iOS中所有能看到的内容都是view或者其子类

    //@property (retain, nonatomic) UIWindow *window;//ARC默认是strong   MRC是retain
    //AppDelegate.m中代码
    #import "AppDelegate.h"
    
    @implementation AppDelegate
    -(void)dealloc
    {
        [_window release];
        [super dealloc];
    }
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        
        //第一步创建视图    //视图默认是透明色  clearcolor
        UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
        //第二步,配置视图
    //    [redView setBackgroundColor:[UIColor redColor]];//两种设置颜色的方式
        redView.backgroundColor = [UIColor redColor];
        //第三步,添加视图
        [self.window addSubview:redView];
    //    [_window addSubview:redView];//两种方式添加
        //第四步,内存管理
        [redView release];
        
    
        
        [self.window makeKeyAndVisible];
        return YES;
    }
    UI是使用 UIkit framework  框架
    UIView分四类

    如何呈现一个内容

    可以响应触摸事件
    做动画
    画东西,涂鸦
    创建视图的步骤如下:
 1、开辟空间并初始化视图(初始化时,给出视图位置和大小)
 2、对视图做⼀一些设置(⽐如:背景颜色)
 3、将视图添加到window上进行显示4、释放视图对象
    1.ARC——>MRC
    2.strong——>retain
    3.dealloc
    4.添加autorelease
    frame
    frame是view得重要属性,是我们做视图布局的关键,它决定了视图的大小和位置
    ceter(中心点)
    center.x = frame.x+frame.width/2;//center的x坐标
    center.y = frame.y+frame.height/2//center的y坐标
    bounds
    bounds(边界)也是view的重要属性,用于定义自己的边界,它同frame一样是一个CGRect结构体变量
    当一个view设置bounds时,会把自己当成一个容器,定义自己的边界大小以及相对坐标原点的偏移量
    当子视图添加到此视图时,会根据bounds指定的原点计算frame
    center发生变化bounds.origin不变   bounds.orgin发生变化,center不变
    添加视图
    管理视图层次
    视图重要属性
    五.UILabel
    UILabel(标签):是显示文本的控件在App中出现频率最高
    UILabel是UIView得子类       UILabel是能显示文字的视图
     
    文本显示:在视图上显示文字
        UILabel *aView = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 100, 100];
    //    aView.backgroundColor = [UIColor redColor];
        aView.text = @"用户名:";
        [_window addSubview:aView];
        [aView release];

    控制文本显示

    六.UITextField

    UITextField(输⼊框):是控制⽂本输入和显示的控件。在App中UITextField

    出现频率也比较高。

    iOS系统借助虚拟键盘实现输入,当点击输入框,系统会⾃动调出键盘,⽅便 你进⼀步操作。在你不需要输入的时候,可以使⽤用收回键盘的方法,收回弹出的

    键盘。 UITextField和UILabel相比,UILabel主要⽤用于文字显示,不能编辑,

    UITextField允许⽤户编辑文字(输入)。

    UITextField *bView = [[UITextField alloc] initWithFrame:CGRectMake(30, 30, 100, 100)];
        bView.borderStyle = UITextBorderStyleRoundedRect;//圆角边框
        bView.placeholder = @"请输入您的用户名";//输入框中提示输入内容
        [_window addSubview:bView];
        [bView release];

    文本显示

    输入控制

    外观控制

    七.UIButton

     创建UIButton与创建UILabel、UITextField、UIView的步骤很相似。


    1、创建button对象(如果本类有初始化⽅法,使⽤⾃己的;否则使⽤父类的)。


    2、设置按钮显⽰相关的属性


    3、为按钮添加点击事件
 

    4、添加按钮到⽗视图上,⽤以显示


    5、按钮无需释放(因为使用的是类方法创建的button)

     UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
     loginButton.frame = CGRectMake(30, 200, 60, 30);
     [loginButton setTitle:@"登录" forState:UIControlStateNormal];
     [loginButton addTarget:self action:@selector(login:)
     forControlEvents:UIControlEventTouchUpInside];
     [containerView addSubview:loginButton];

    UIButton添加事件

    外观控制

  • 相关阅读:
    检测ORACLE方法汇总数据块损坏
    DHot.exe 热点新闻
    无效 URI: 故障分析证书颁发机构/主机
    lucene两个分页操作
    求职技巧—2014六个秘诀二
    ubuntu下一个rootusername入口mysql,如何查看username和password,如何改变rootpassword
    LeetCodeOJ. Maximum Depth of Binary Tree
    基于用户的推荐协同过滤算法的算法
    《C++ Primer Plus》学习笔记10
    m_Orchestrate learning system---八、下拉列表(select标签)如何实现链接功能
  • 原文地址:https://www.cnblogs.com/limicheng/p/3832952.html
Copyright © 2011-2022 走看看