iOS基础-UIView

  //创建一个窗口,设置大小为屏幕大小
    self.window =[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    //设置窗口的背景颜色
//    UIImage *myImage = [UIImage imageNamed:@"ppp"];

    self.window.backgroundColor = [UIColor colorWithRed:0.06 green:0.47 blue:0.48 alpha:0.9];
    //使其成为主窗口,且可见
    [self.window makeKeyAndVisible];

    UIImage *image = [UIImage imageNamed:@"logo.png"];
    UIImageView *imageview = [[UIImageView alloc]initWithImage:image];
    imageview.frame = CGRectMake(0, 0, 450, 680);
    [self.window addSubview:imageview];
    [imageview release];

    UIImage *qq = [UIImage imageNamed:@"qq.png"];
    UIImageView *imageqq = [[UIImageView alloc]initWithImage:qq];

    //UIView就是屏幕上的一个矩形区域
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(80, 120, 100, 30)];
    view.backgroundColor = [UIColor colorWithRed:0.6 green:0.46 blue:0.2 alpha:1];
    [self.window addSubview:view];

    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(200, 120, 100, 30)];
    view2.backgroundColor = [UIColor colorWithRed:0.6 green:0.46 blue:0.2 alpha:1];
    [self.window addSubview:view2];

    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(140, 250, 100, 30)];
    view3.backgroundColor = [UIColor colorWithRed:0.6 green:0.46 blue:0.2 alpha:1];
    [self.window addSubview:view3];

    //一个视图可以有多个子视图,但只有一个父视图,父视图和子视图是相对而言的。
    UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(15, 5, 70, 20)];
    view4.backgroundColor = [UIColor blackColor];
    [view addSubview:view4];

    UIView *view5 = [[UIView alloc]initWithFrame:CGRectMake(15, 5, 70, 20)];
    view5.backgroundColor = [UIColor blackColor];
    [view2 addSubview:view5];

    UIView *view6 = [[UIView alloc]initWithFrame:CGRectMake(170, 200, 20, 20)];
    view6.center = CGPointMake(200, 200);//中心点,相对于父视图而言
    view6.backgroundColor = [UIColor redColor];
    [self.window addSubview:view6];

//    UIView *greenV = [[UIView alloc]initWithFrame:CGRectMake(250, 250, 100, 100)];
//    greenV.backgroundColor = [UIColor grayColor];
//    [self.window addSubview:greenV];
//    //bounds的orign默认为(0,0),是相对于当前视图的左上角的距离
//    greenV.bounds = CGRectMake(30, 0, 100, 100);
//
//
//    UIView *blackV = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)];
//    blackV.backgroundColor = [UIColor blackColor];
//    [self.window addSubview:blackV];
//    //将一个视图加入到另一个视图中,greenv兑redv有所有权,redv的引用计数加1,
//    [greenV addSubview:blackV];

    UIView *view01 = [[UIView alloc]initWithFrame:CGRectMake(100, 400, 100, 100)];
    view01.backgroundColor = [UIColor brownColor];
    [self.window addSubview:view01];

    UIView *view02 = [[UIView alloc]initWithFrame:CGRectMake(120, 410, 100, 100)];
    view02.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:view02];

    UIView *view03 = [[UIView alloc]initWithFrame:CGRectMake(110, 430, 100, 100)];
    view03.backgroundColor = [UIColor purpleColor];
//    [self.window addSubview:view03];

//    [self.window insertSubview:view03 atIndex:3];
    [self.window insertSubview:view03 aboveSubview:view01];
//    [self.window insertSubview:view03 belowSubview:view01];

    UIView *viewWhite = [[UIView alloc]initWithFrame:CGRectMake(130, 450, 100, 100)];
    viewWhite.backgroundColor = [UIColor whiteColor];
    [self.window insertSubview:viewWhite belowSubview:view03];

    [self.window bringSubviewToFront:imageview];
    [self.window sendSubviewToBack:imageview];
    [self.window exchangeSubviewAtIndex:7 withSubviewAtIndex:9];
    // 从父视图中移除
//    [viewWhite removeFromSuperview];

    NSArray *arr = [self.window subviews];
    NSLog(@"%ld",[arr count]);

    viewWhite.alpha = 0.5;
    view03.alpha = 0.5;
    view02.alpha = 0.5;
    view01.alpha = 0.5;

    viewWhite.tag = 10;
    UIView *copyView = [self.window viewWithTag:10];
    [self.window insertSubview:copyView belowSubview:view01];
    copyView.backgroundColor = [UIColor orangeColor];

    UIView *view001 = [[UIView alloc]initWithFrame:CGRectMake(0, 300, 50, 100)];
    view001.backgroundColor = [UIColor redColor];
    UIView *view002 = [[UIView alloc]initWithFrame:CGRectMake(50, 300, 50, 100)];
    view002.backgroundColor = [UIColor greenColor];
    UIView *view003 = [[UIView alloc]initWithFrame:CGRectMake(100, 300, 50, 100)];
    view003.backgroundColor = [UIColor blueColor];
    UIView *view004 = [[UIView alloc]initWithFrame:CGRectMake(150, 300, 50, 100)];
    view004.backgroundColor = [UIColor cyanColor];
    UIView *view005 = [[UIView alloc]initWithFrame:CGRectMake(200, 300, 50, 100)];
    view005.backgroundColor = [UIColor yellowColor];
    UIView *view006 = [[UIView alloc]initWithFrame:CGRectMake(250, 300, 50, 100)];
    view006.backgroundColor = [UIColor magentaColor];
    UIView *view007 = [[UIView alloc]initWithFrame:CGRectMake(300, 300, 50, 100)];
    view007.backgroundColor = [UIColor orangeColor];
    UIView *view008 = [[UIView alloc]initWithFrame:CGRectMake(350, 300, 50, 100)];
    view008.backgroundColor = [UIColor purpleColor];
    imageqq.frame = CGRectMake(80, 200, 50, 50);
    imageqq.backgroundColor = [UIColor clearColor];

//    NSArray *array = [[NSArray alloc]initWithObjects:view001,view002,view003,view004,view005,view006,view007, nil];
    [self.window addSubview:view007];
    [self.window addSubview:view006];
    [self.window addSubview:view005];
    [self.window addSubview:view004];
    [self.window addSubview:view003];
    [self.window addSubview:view002];
    [self.window addSubview:view001];
    [self.window addSubview:view008];
    [self.window addSubview:imageqq];

    [imageqq release];
    [view008 release];
    [view007 release];
    [view006 release];
    [view005 release];
    [view004 release];
    [view003 release];
    [view002 release];
    [view001 release];

    [viewWhite release];
    [view03 release];
    [view02 release];
    [view01 release];
时间: 2024-07-28 18:08:08

iOS基础-UIView的相关文章

iOS基础--UIView的常见属性

UIView的常见属性以及方法 @property(nonatomic,readonly) UIView *superview; // 获得自己的父控件对象 @property(nonatomic,readonly,copy) NSArry *subviews; // 获得自己的所有子控件对象 @property(nonatomic) NSInterger tag; // 控件的ID(标识),父控件可以通过tag来找到对应的子控件 @property(nonatomic) CGAffineTra

iOS基础问答面试

<简书社区 — Timhbw>iOS基础问答面试题连载(一)-附答案:http://www.jianshu.com/p/1ebf7333808d <简书社区 — Timhbw>iOS基础问答面试题连载(二)-附答案:http://www.jianshu.com/p/ce50261f8907 <简书社区 — Timhbw>iOS基础问答面试题连载(三)-附答案:http://www.jianshu.com/p/5fd65c20912e 以下是一些自己收集的比较基础的问题(

iOS基础——通过案例学知识之LaunchScreen、APPIcon、StatusBar、UIScrollView、UIPageControl

iOS基础--通过案例学知识之LaunchScreen.APPIcon.StatusBar.UIScrollView.UIPageControl 今天要实现的案例效果图 一.LaunchScreen 1.设置程序的LaunchScreen 在项目配置文件中配置启动页,并且在LaunchScreen.storyboard中进行布局 2.设置LaunchScreen时间 //单位:秒 [NSThread sleepForTimeInterval:1.5f]; 二.APPIcon 1.命名规则:iOS

[iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表&quot;练习)

A.概述 在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能 1.按钮点击后,显示为“已下载”,并且不可以再按 2.在屏幕中间弹出一个消息框,通知消息“xx已经被安装”,慢慢消失 3.消息框样式为圆角半透明 B.不使用代理模式,使用app空间组和主View之间的父子View关系 1.在主View中创建一个消息框 主View控制器:ViewController.m 1 // 创建下载成功消息框 2 CGFloat labelWid

iOS基础问答面试题连载(一)-附答案

「Tim的博客」iOS基础问答面试题连载(一)-附答案 「Tim的博客」iOS基础问答面试题连载(二)-附答案 「Tim的博客」iOS基础问答面试题连载(三)-附答案 「Tim的博客」iOS基础问答面试题连载(四) 以下是一些自己收集的比较基础的问题(大神可以忽略),附上答案,方便大家阅读.俗话说得好,基础不牢,地动山摇.文章末尾会提供PDF版的文档,方便大家木有网的时候也可以用移动设备观看. 1.简单的描述下类扩展和分类的区别?(说2点) 类扩展没有名字,分类有名字. 类扩展可以为某个类增加额

ios基础-XCode使用技巧

(一)代码规范pragma mark 1.定义 #pragma 开头的代码是一条编译器指令,是一个特定于程序或编译器的指令.不一定适用于其它编译器或其它环境.如果编译器不能识别该指令,则会将其忽略. 2.作用 在编辑器窗格顶部,方法和函数弹出菜单中将代码分隔开,规范化代码,方便阅读查找. 3.使用 在需要加注释的地方加上#pragma mark - #pragma mark - 视图将要显示的时候 - (void)viewWillAppear:(BOOL)animated { //初始化选号的数

IOS将UIView转化为UIImage

+(UIImage*)createImageFromView:(UIView*)view { //obtain scale CGFloat scale = [UIScreen mainScreen].scale; 开始绘图,下面方法,第一个参数表示区域大小.第二个参数表示是否是非透明的.如果需要显示半透明效果,需要传NO,否则传YES.第三个参数就是屏幕密度了 UIGraphicsBeginImageContextWithOptions(CGSizeMake(view.frame.size.wi

iOS 基础函数解析 - Foundation Functions Reference

Foundation Functions Reference Framework Foundation/Foundation.h Declared in NSBundle.h NSByteOrder.h NSDecimal.h NSException.h NSObjCRuntime.h NSObject.h NSPathUtilities.h NSRange.h NSZone.h Overview This chapter describes the functions and function

iOS基础 KVC和KVO

疯狂IOS讲义这本书之前一直一直觉得没什么用,看了做不出像样的程序出来,但是经过几天的学习发现,没有一定的ios基础,做的程序永远都是在模仿他人的程序,把他人的代码复制 粘贴...为什么能够实现?原理 是什么?不懂...所以 必须懂原理,为什么? 接下来就今天所学习的内容做一个小结: 首先介绍一下KVO和KVC,一个是键值编码一个是键值监听,我第一次听这个也是很困惑,这是个神马意思?键值是啥?监听 还懂一点 ... 我们都知道之前我们都是通过setter和getter来设置和修改对象的属性,KV