1、首先:在UI里面我们使用的是MRC,需要把ARC改成NO;
若学习比较吃力,可以先学习一下基础:

则需要修改AppDelegate.h
#import

@interface

AppDelegate :
UIResponder
<</span>UIApplicationDelegate>

@property
(retain,

nonatomic)

UIWindow *window;

//将strong改成retain

@end
同时AppDelegate.m中要写dealloc
- (void)dealloc
{
   
[_window

release];———》可以写成self.window = nil;
//省掉释放和指向nil两步

   
[super

dealloc];

}
2、 当应用程序加载完成的时候触发,此时如果你想让应用程序在加载的时候显示内容,就在该方法中写入要显示的内容
- (BOOL)application:(UIApplication

*)application didFinishLaunchingWithOptions:(NSDictionary

*)launchOptions {

//创建应用程序的窗口,self.Window
是本应用窗口对象,重要作用将内容呈现给用户

//UIScreen 屏幕类,[UIScreen mainScreen]获取主屏幕,[UIScreen mainScreen]
bounds]获取主屏幕的大小

//UIColor 颜色类

self.window

= [[[UIWindow

alloc]

initWithFrame:[[UIScreen

mainScreen]

bounds]
]autorelease];

//对于屏幕上看到的内容都是UIView及UIView的子类

//UIView代表屏幕上的一块矩形区域

//如果屏幕上绘制出一块矩形区域,需要知道屏幕左上角坐标,即屏幕坐标系原点,还有矩形的宽和高





 
  3、 快速创建出结构体变量分四步:

    
CGRect (位置,大小)

    
--------CGRectMake();

    
CGPoint(点)

    
--------CGPointMake();

    
CGSize(大小)

    
--------CGSizeMake();

 
 

//1.创建UIView
对象

UIView
*redView = [[UIView

alloc]initWithFrame:CGRectMake(50,

50,

100,

100)];

//3.修改视图的背景颜色,默认颜色是透明色

[redView
setBackgroundColor:[UIColor

redColor]];

//4.添加到父视图上——即添加在板报上

[self.window

addSubview:redView];

//2.释放所有权

[redView
release];

 
  练习1创建一个绿色视图,添加到self.window上

UIView
*greenView =[[UIView

alloc]initWithFrame:CGRectMake(150,

50,

100,

100)];

[greenView
setBackgroundColor:[UIColor

greenColor]];

   
[self.window
addSubview:greenView];
   
[greenView release];



 4、想查看屏幕大小不需要记忆,可以获取屏幕大小后打印即可,想查看不同的大小屏幕大小,只需要更改设备名称
 
  
 
CGRect
newRect = [[UIScreen

mainScreen]

bounds];

 
   
//将结构体变量转为字符串对象输出

//NSStringFromCGRect()

//NSStringFromCGPoing()

//NSStringFromCGSize()

   
NSLog(@"%@",NSStringFromCGRect(newRect));
     
//建立内部绿色视图

// Override point for customization after application
launch.

//设置self.window.backgroundColor 的背景颜色

self.window.backgroundColor

= [UIColor

cyanColor];

//将self.window 设置为应用的主屏幕并使其可见

   
[self.window
makeKeyAndVisible];

return
YES;

}
==============================================
5、#pragma mark -
 //#pragma mark
-后面加一个-,表示在分组的基础上又进行了分块。
6、
UIView 的重量级属性:frame center bounds
frame:包含(origin左上角的坐标以及size矩形区域的大小),主要用来控制一个视图的位置和大小,其中位置相对于父视图原点坐标的x,y轴上的距离

//center
:中心点,视图的中心点的坐标,相对于父视图坐标原点的位置

//center.x = frame.origin.x + frame.size.width / 2;

   
//center.y =
frame.origin.y + frame.size.width / 2;

//center 改变,frame也变 ,frame改变,center 也改变

//bounds,
一个视图的边界,CGRect(origin,size),origin是矩形区域所占的相对于自身坐标系的原点位置,size是矩形区域的大小,一个视图创建出来后默认bounds的origin的位置和自身视图的原点是重合的;bounds的(size)大小和frame的(size)大小是一样的;修改一个视图的bounds
的origin(x,y)的时候,视图的frame不变,center也不变;修改一个视图的size,frame变化,center不变;

//修改bounds
的origin的影响的自身原点的坐标位置,也既是影响自身子视图的位置

 7、#pragma
mark 修改一个视图的Frame

//redView

UIView
*redView = [[UIView

alloc]initWithFrame:CGRectMake(60,

184,

200,

200)];

//定义一个矩形的结构体变量

//   
CGRect rect = CGRectMake(100, 100, 100, 200);

//   
redView.frame = rect;

//视图的frame不能被单个修改,只能整体赋值

//   
redView.frame.origin.x = 100;

//   
CGRect rect1 = redView.frame;

//   
rect1.origin.x = 100;

//   
rect1.origin.y = 100;

//   
redView.frame = rect1;

8、#pragma mark
修改一个视图的senter
//   
NSLog(@"%@",NSStringFromCGPoint(redView.center));

//   
CGPoint center = CGPointMake(100, 100);

//   
redView.center = center;

//   
NSLog(@"%@",NSStringFromCGRect(redView.frame));

9、#pragma mark
修改一个视图的bounds
//   
redView.bounds = CGRectMake(0, 0, 200, 200);

//   
NSLog(@"%@",NSStringFromCGRect(redView.bounds));


   
redView.backgroundColor

= [UIColor

redColor];

[self.window

addSubview:redView];

[redView
release];

 
  

//greenView

UIView
*greenView = [[UIView

alloc]initWithFrame:CGRectMake(110,

234,

100,

100)];

greenView.backgroundColor

= [UIColor

greenColor];

[self.window

addSubview:greenView];

[greenView
release];

//blueView

UIView
*blueView = [[UIView

alloc]initWithFrame:CGRectMake(85,

209,

150,

150)];

blueView.backgroundColor

= [UIColor

blueColor];

[self.window

addSubview:blueView];

[blueView
release];

   

 10、
 调整视图关系的方法1
//insertSubview :A 
aboveSubview: 
B   
在B视图上插入A视图
//   
[self.window insertSubview:greenView
aboveSubview:blueView];

      
  
   
//insertSubview:A
belowSubview:B   在B视图下插入A视图
  
[self.window insertSubview:blueView
belowSubview:greenView];

//insertSubview:A atIndex:下标  
将A视图添加到指定位置

[self.window

insertSubview:greenView

atIndex:2];

   
//或者 
[self.window insertSubview:blueView atIndex:1];
        
  11、

//调整视图关系的方法2

    1、//bringSubviewToFront:A 
. 将A调整到所有子视图的最前面

   
[self.window
bringSubviewToFront:redView];

 
     
     
 
     
     
  
    2、//sendSubviewToBack:A
  . 将A调整到所有子视图的最后面
   
[self.window
sendSubviewToBack:redView];

 
    

//exchangeSubviewAtIndex:下标1
withSubviewAtIndex:下标2,交换两个指定位置的子视图

   
[self.window
exchangeSubviewAtIndex:1
withSubviewAtIndex:2]; 
 
 
     
   

//[A   removeFromSuperview ]
A视图从父视图中移除

   
[blueView removeFromSuperview];
 
 
=================================================
 
  总结:
 
 
 视图的层级关系:
    
1.最后添加的子视图肯定在所有视图的最前面

    
2.子视图永远在父视图的前面

    
3.子视图的添加是有顺序的
    
4.父视图通过subviews 数组管理所有的子视图
    
5.如果想调整视图之间的层级关系,需要通过父视图来调整
    
6.如果想从父视图中移除,使用将要移除的对象来调用方法
 
 =============================================
 
   

   12、定时器

//第一个参数 设置每过多长时间执行一次定时操作

//第二参数 有谁来执行操作

//第三个参数 选择执行的操作

//第四个参数 用户信息 nil

//第五个参数 是否需要重复定义器操作

[NSTimer

scheduledTimerWithTimeInterval:0.5

target:self

selector:@selector(printHelloword)

userInfo:nil

repeats:YES];

 
  
 
//以上程序结束

self.window.backgroundColor

= [UIColor

whiteColor];

[self.window

makeKeyAndVisible];

return
YES;

}
#pragma mark 实现选择器中方法
-
(void)printHelloword{
   
NSLog(@"你好");
————————————————————————————
经典霓虹灯的制作:



分析:
15*(1 + 0)  
   15*(1 + 0)
 290- 15*2*0    
 538- 15*2*0
15*(1 + 1)  
   15*(1 + 1)
 290- 15*2*1    
 538- 15*2*1
15*(1 + 2)  
   15*(1 + 2)
 290- 15*2*2    
 538- 15*2*2
15*(1 + 3)  
   15*(1 + 3)
 290- 15*2*3    
 538- 15*2*3
15*(1 + 4)  
   15*(1 + 4)
 290- 15*2*4    
 538- 15*2*4
15*(i+1)  
     
   15*(i+1)  
 
  290 - i*15*2  
  538 - i*15*2)

#define kColorValue arc4random_uniform(255)/255.0
#import

"AppDelegate.h"

@interface
AppDelegate
()
@end
@implementation
AppDelegate

- (void)dealloc

{

   
self.window
=
nil;

[super
dealloc];

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

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

//
Override point for customization after application
launch.

   
self.window.backgroundColor
=
[UIColor
whiteColor];

[self.window
makeKeyAndVisible];

 
 ————————————————————————————
   
for
(int
i
= 0;
i <</span> 10;
i ++) {

       
UIView
*view
= [[UIView
alloc]initWithFrame:(CGRectMake(15*(i+1),15*(i+1),
290
-
i*15*2,
538
-
i*15*2))];

[self.window
addSubview:view];

view.backgroundColor
=
[UIColor
colorWithRed:kColorValue
green:kColorValue
blue:kColorValue
alpha:1];

view.tag
=
100+i;

       
[view release];
 
}
   
[NSTimer
scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(fromOutToInside)
userInfo:nil
repeats:YES];
 
return
YES;
}
—————————————————————————————
-
(void)fromOutToInside{

UIColor
*temp
= [self.window
viewWithTag:100
+
9].backgroundColor;

for
(int
i
= 100
+
9;
i >= 100;
i--) {

       
[self.window
viewWithTag:i].backgroundColor
=
[self.window
viewWithTag:i-1].backgroundColor;

   
}
   
[self.window
viewWithTag:100].backgroundColor
=
temp;  
}

—————————————————————————————————————————————

欢迎学习本文,未经博主同意禁止转载!
}

UIView、UIViewLayout&nbsp;UI_01的更多相关文章

  1. [BS-26] UIView、pop和Core Animation区别

    UIView.pop和Core Animation区别 一.UIView.pop和Core Animation的主要区别 1. Core Animation的动画只能添加到layer上(layer.p ...

  2. ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)

    Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...

  3. 有关UIView、subview的几个基础知识点-IOS开发 (实例)

    环境是xcode4.3 首先要弄懂几个基本的概念. 一)三个结构体:CGPoint.CGSize.CGRect 1.  CGPoint /* Points. */ struct CGPoint { C ...

  4. iOS:UIView、UIControl、UIButton、UILabel简单的属性和方法常识

    常见属性和方法 一 .UIVIew 常见属性 1.frame 位置和尺寸(以父控件的左上角为原点(0,0)) 2.center 中点 (以父控件的左上角为原点(0,0)) 3.bounds 位置和尺寸 ...

  5. iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控

    -- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事 ...

  6. 你真的了解UIEvent、UITouch吗?

    一:首先查看一下关于UIEvent的定义 //事件类型 typedef NS_ENUM(NSInteger, UIEventType) { UIEventTypeTouches, UIEventTyp ...

  7. 详解CALayer 和 UIView的区别和联系

    详解CALayer 和 UIView的区别和联系   前言 前面发了一篇iOS 面试的文章,在说到 UIView 和 CALayer 的区别和联系的时候,被喵神指出没有切中要点,所以这里就 CALay ...

  8. iOS-触摸事件、手势识别、摇晃事件、耳机线控

    概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事件(手势操作).运动事件. ...

  9. iOS - UIView

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView : UIResponder <NSCoding, UIAppearance, UIAppeara ...

随机推荐

  1. Spring Boot消息队列应用实践

    消息队列是大型复杂系统解耦利器.本文根据应用广泛的消息队列RabbitMQ,介绍Spring Boot应用程序中队列中间件的开发和应用. 一.RabbitMQ基础 1.RabbitMQ简介 Rabbi ...

  2. jQuery – AJAX load() 方法

    jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. load() 方法从服务器加载数据,并把返回的数据放入被选元素中. 语法: $(selector). ...

  3. Python3 教程

    Python的3.0版本,常被称为Python 3000,或简称Py3k.相对于Python的早期版本,这是一个较大的升级.为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下兼容. 查 ...

  4. XCode使用技巧

    XCode使用技巧 自动生成get.set方法 @property 用法 #import <Foundation/Foundation.h> @interface People : NSO ...

  5. Android音频处理——通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能

    Android音频处理--通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能 音频这方面很博大精深,我这里肯定讲不了什么高级的东西,最多也只是一些基础类知识,首先,我们要介绍一下 ...

  6. springMVC源码分析--AbstractControllerUrlHandlerMapping(六)

    上一篇博客springMVC源码分析--AbstractDetectingUrlHandlerMapping(五)中我们介绍了AbstractDetectingUrlHandlerMapping,其定 ...

  7. FORM开发之键性弹性域开发

    1.创建表时带有键弹性域字段 SUMMARY_FLAG VARCHAR2(1) , /* 必须有此字段 */ ENABLED_FLAG VARCHAR2(1) , /* 必须有此字段 */ START ...

  8. 手把手图文并茂教你发布Android开源库

    转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼,文章链接: http://blog.csdn.net/hejjunlin/article/details/52452220 经常逛githu ...

  9. 全文检索 Lucene(4)

    经过了前面几篇文章的学习,我们基本上可以适用Lucene来开发我们的站内搜索应用了.但是观察一下目前的主流的搜索引擎,我们会发现查询结果会有高亮的显示效果.所以,今天我们就来学习一下,给Lucene添 ...

  10. 集成JPA+springmvc+spring+EJB中的Java EE应用

    EJB是sun的JavaEE服务器端组件模型,设计目标与核心应用是部署分布式应用程序.凭借java跨平台的优势,用EJB技术部署的分布式系统可以不限于特定的平台.EJB (Enterprise Jav ...