zoukankan      html  css  js  c++  java
  • IOS开发之UIview

    #import "AppDelegate.h"

    #import "ViewController.h"

    #import "stdlib.h"

    @interface AppDelegate (){

        UIView *view1;

        

    }

    @end

    @implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //UIkit  框架——》包含了所有可以看的见的视图控件

    //UIwindow:

    //UIView:

        

    //    UIwindow:窗口——》ios应用程序里面只能有一个主窗口    有并且只能有一个主窗口

    //               是用来显示承载可以看见的控价的容器   因为所有的控件都是一层层添加到窗

    //               口上的。

    //            :初始化   initWithFrame构造方法——在创建一个对象的时候   同时给他一个

    //                      Frame;

    //       获取屏幕边境范围:[UIScreen mainScreen].bounds

        

    //UIView:是一个视图——是所有视图类的父类

    //UIwindow:也属于视图

        self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

        

        ViewController *vc = [[ViewController alloc]init];

        

        self.window.rootViewController = vc;

        

        

    //    makeKeyAndVisible  让窗口是作为主窗口   并且是显示在主频幕上

        [self.window makeKeyAndVisible];

        self.window.backgroundColor = [UIColor brownColor];

    /*.

    //    1.视图的创建

          UIView *view = [[UIView alloc]init];

          UIView *view1 = [[UIView alloc]init];

          UIView *view2 = [[UIView alloc]init];

          UIView *view3 = [[UIView alloc]init];

        UIView *view4 = [[UIView alloc]init];

    //    视图的位置和自身的大小

    //    frame - 位置

    //    由很多的像素点组成的

    //    视图的起始位置:orign

    //    窗口的起始位置是左上角 (坐标(0,0))

    //    所有子视图都是根据orign(原点,起始点)来定位起始位置的

    //    size —— 尺寸视图本身的大小

    //    frame —— 是视图中的一个属性

    //    CGRect:

        

        view.frame =CGRectMake(0, 0, 200, 200);

        view1.frame =CGRectMake(200, 200, 100, 100);

        view2.frame =CGRectMake(300, 300, 200, 100);

        view3.frame =CGRectMake(200, 400, 100, 100);

        view4.frame =CGRectMake(0, 500, 200, 200);

    //    背景颜色

    //    UICOlor -》 颜色类

        view.backgroundColor = [UIColor blueColor];

        view1.backgroundColor = [UIColor redColor];

        view2.backgroundColor = [UIColor whiteColor];

        view3.backgroundColor = [UIColor purpleColor];

        view4.backgroundColor = [UIColor yellowColor];

    //      添加到父视图——如果没有这个方法  创建的视图将不会被显示在屏幕上

    //    [父视图  addSubView:要添加的视图];

        [self.window addSubview:view];

        [self.window addSubview:view1];

        [self.window addSubview:view2];

        [self.window addSubview:view3];

        [self.window addSubview:view4];

    // 设置视图透明度

    //   0.0(完全透明《所有属性方法类似被禁用》) -1。0(不透明)

        view.alpha = 0.71;

    // 设置hidden:隐藏   默认值是0;不隐藏

        view.hidden = 0;

        NSLog(@"%d",view.isHidden);

    //  设置阴影

    //  图层之间的关系

    //  视图是一层层叠加到一个父视图上的

    //  父视图   是一个承载体

    //  子视图   是父视图里面的一个元素  当父视图的位置发生改变的时候 子视图也会发生改变

        */

       /* UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 110, 200, 200)];

        view.backgroundColor = [UIColor cyanColor];

        [view addSubview:view];

        

        UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];

        view1.backgroundColor = [UIColor redColor];

        [view addSubview:view1];*/

    //    frame:是根据他的父视图来定义这个视图本身位置的

     /*

       UIView *view0 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 500, 800)];

        view0.backgroundColor = [UIColor brownColor];

        [self.window addSubview:view0];*/

     /*

        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 110, 200, 200)];

        view.backgroundColor = [UIColor cyanColor];

        [self.window addSubview:view];

        

        UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 180, 180)];

        view1.backgroundColor = [UIColor redColor];

        [view addSubview:view1];

       

    //    center 中心点   对角线的交点

    //    center.x= 宽/2+原点的x

    //    center.y = 高/2+原点的y

        

        view.center = CGPointMake(150, 200);//改变中心点可以改变视图的位置

    //    只能使用frame 在创建视图的时候给他一个位置

    //   相对于自身的位置 原点永远是(0,0)

    //    bouns 自身的边境范围   是获得视图的宽高  忽略原点

        

            NSLog(@"%f",view.bounds.size.width);

        

    // 定时器   隔多少秒 去做某件事

    //  NSTimer  定时器的类

    //    定时器初始化的方法

    //   TimeInterval:时间间隔   单位是秒

    //   selector:方法选择器  用来选择一个方法来执行

    //   repeats:重复次数

    //   target:让谁执行

    //    隔一秒钟执行一次start方法  重复执行

        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(start) userInfo:nil repeats:YES];

        */

        

         /*  [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(start) userInfo:nil repeats:YES];

        

           [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(start1) userInfo:nil repeats:YES];

         */

        

    //  在同一个父视图中

    //    1.view1 移动到最上面

    //   [self.window bringsubviewToFront:view1];

    //      把一个视图移到底下

    //   [self.window sendsubviewToFront:view2]

    //      交换两个视图的位置

    //        self.window exchangeSubviewAtIndex:2 withSubviewAtIndex:1

        

    //    subview (所有子视图组成的数组)数组-》

    //    self.window.subviews

        

    //    初始化视图的顺序  就是把视图存放到subviews这个数组里面的顺序

    //    改变视图的胡须就是在改变subviews数组里面元素的位置

    //   插入一个视图  到另一个视图的上面

        UIView *inserview = [[UIView alloc]initWithFrame:CGRectMake(80, 250, 80, 80)];

        inserview.backgroundColor = [UIColor greenColor];

        [self .window addSubview:inserview];

        [self.window insertSubview:inserview atIndex:2];

    //    插入到哪一个视图的下面

        [self.window insertSubview:inserview belowSubview:view1];

        

    //    tag:标记   标签  标号——》同一个父视图里面的身份证号

        inserview.tag = 100;

    //    可以通过tag值在父视图上找到这个视图

    //    viewwithTag:在一个父视图上面  查找有没有tag值是多少的视图

        UIView *v = [self.window viewWithTag:100];

    //    移除视图

        [v removeFromSuperview];

        

        

         [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(start) userInfo:nil repeats:YES];

        

        

        return YES;

    }

    -(void)start{for (int i=0; i<1; i++) {

        

        

        int x1;

        x1 = arc4random()%200;

        

        

        UIView *view = [[UIView alloc]init];

        

        view.frame = CGRectMake(x1, x1+20, x1+20, x1+20);

        NSArray *colorList =[[NSArray alloc]init];

        colorList = @[[UIColor redColor],[UIColor blackColor],[UIColor blueColor],[UIColor purpleColor],[UIColor grayColor],[UIColor darkGrayColor],[UIColor lightGrayColor],[UIColor whiteColor],[UIColor greenColor],[UIColor cyanColor],[UIColor yellowColor],[UIColor orangeColor],[UIColor magentaColor],[UIColor brownColor],[UIColor clearColor]];

        int p = arc4random()%14;

        view.backgroundColor = colorList[p];

        view.alpha = 0.5;

        [self.window addSubview:view];

        

    }

    }

    /*-(void)start1{

        NSArray *colorList =[[NSArray alloc]init];

        colorList = @[[UIColor redColor],[UIColor blackColor],[UIColor blueColor],[UIColor purpleColor],[UIColor grayColor],[UIColor darkGrayColor],[UIColor lightGrayColor],[UIColor whiteColor],[UIColor greenColor],[UIColor cyanColor],[UIColor yellowColor],[UIColor orangeColor],[UIColor magentaColor],[UIColor brownColor],[UIColor clearColor]];

        

        

       UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(50, 50,250 , 250)];

        int i = arc4random()%14;

        view2.backgroundColor = colorList[i];

        view2.alpha = 0.5;

        [self.window addSubview:view2];

    }

    - (void)start{

       

        NSArray *colorList =[[NSArray alloc]init];

        colorList = @[[UIColor redColor],[UIColor blackColor],[UIColor blueColor],[UIColor purpleColor],[UIColor grayColor],[UIColor darkGrayColor],[UIColor lightGrayColor],[UIColor whiteColor],[UIColor greenColor],[UIColor cyanColor],[UIColor yellowColor],[UIColor orangeColor],[UIColor magentaColor],[UIColor brownColor],[UIColor clearColor]];

         view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0,150 , 150)];

        int i = arc4random()%14;

        view1.backgroundColor = colorList[i];

        view1.alpha = 0.5;

         [self.window addSubview:view1];

    }*/

  • 相关阅读:
    python定位一组元素并打印出文本
    python+selenium自动化报告HTMLTestRunner增加饼图展示
    PyCharm链接Oracle数据库
    python+selenium自动化鼠标事件之封装
    python学习记录--默认字典defaultdict()
    python学习记录--有序字典OrderedDict()
    python学习记录--Counter()类
    python学习记录--集合
    python学习记录--字典
    python学习记录--列表
  • 原文地址:https://www.cnblogs.com/Biaoac/p/5008418.html
Copyright © 2011-2022 走看看