<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont

简介: 1、首先:在UI里面我们使用的是MRC,需要把ARC改成NO;若学习比较吃力,可以先学习一下基础:http://blog.
1、首先:在UI里面我们使用的是MRC,需要把ARC改成NO;
UIView、UIViewLayout <wbr>UI_01 若学习比较吃力,可以先学习一下基础:

则需要修改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代表屏幕上的一块矩形区域
   
//如果屏幕上绘制出一块矩形区域,需要知道屏幕左上角坐标,即屏幕坐标系原点,还有矩形的宽和高

UIView、UIViewLayout <wbr>UI_01

    3、 快速创建出结构体变量分四步:
     CGRect (位置,大小)
     --------CGRectMake();
     CGPoint(点)
     --------CGPointMake();
     CGSize(大小)
     --------CGSizeMake();

    UIView、UIViewLayout <wbr>UI_01

     //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];
UIView、UIViewLayout <wbr>UI_01

 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];

  UIView、UIViewLayout <wbr>UI_01         UIView、UIViewLayout <wbr>UI_01

  
    //insertSubview:A belowSubview:B   在B视图下插入A视图
   [self.window insertSubview:blueView belowSubview:greenView]; UIView、UIViewLayout <wbr>UI_01
    //insertSubview:A atIndex:下标   将A视图添加到指定位置
    [
self . window insertSubview :greenView atIndex : 2 ];
   //或者   [self.window insertSubview:blueView atIndex:1];
     UIView、UIViewLayout <wbr>UI_01          UIView、UIViewLayout <wbr>UI_01
  11、  //调整视图关系的方法2
    1、
//bringSubviewToFront:A  . 将A调整到所有子视图的最前面
    [self.window bringSubviewToFront:redView]; UIView、UIViewLayout <wbr>UI_01

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

UIView、UIViewLayout <wbr>UI_01       
    //exchangeSubviewAtIndex:下标1 withSubviewAtIndex:下标2,交换两个指定位置的子视图
    [self.window exchangeSubviewAtIndex:1 withSubviewAtIndex:2];  
  UIView、UIViewLayout <wbr>UI_01
           
    //[A   removeFromSuperview ] A视图从父视图中移除
    [blueView removeFromSuperview];
UIView、UIViewLayout <wbr>UI_01

    =================================================
   总结:
     视图的层级关系:
     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(@"你好");
————————————————————————————
经典霓虹灯的制作:
UIView、UIViewLayout <wbr>UI_01

分析:
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;  
}
—————————————————————————————————————————————
欢迎学习本文,未经博主同意禁止转载!
}
目录
相关文章
|
Web App开发 监控 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
Hbase依赖的datanode日志中如果出现如下报错信息:DataXceiverjava.io.EOFException: INFO org.apache.hadoop.hdfs.server.datanode.DataNode: Exception in receiveBlock for block  解决办法:Hbase侧配置的dfs.socket.timeout值过小,与DataNode侧配置的 dfs.socket.timeout的配置不一致,将hbase和datanode的该配置调成大并一致。
764 0
|
Web App开发 前端开发
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
PipeMapRed.waitOutputThreads(): subprocess failed with code X ,这里code X对应的信息如下:error code 1: Operation not perm...
912 0
|
Web App开发 前端开发 测试技术
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
一、迁移步骤 1.首先安装最新版本gitlab(gitlab7.2安装) 2.停止旧版本gitlab服务 3.将旧的项目文件完整导入新的gitlab   bundle exec rake gitlab:import:r...
684 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
service cloudera-scm-agent stop service cloudera-scm-agent stop umount /var/run/cloudera-scm-agent/process umo...
739 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
1.使用lsmod查看ipv6的模块是否被加载。 lsmod | grep ipv6 [root@dmhadoop011 ~]# lsmod | grep ipv6 ipv6                  317340  127 bonding 如果加载了,则进行如下操作: 2.
763 0
|
Web App开发 Java Apache
|
Web App开发 前端开发 Java
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
org.apache.hadoop.hive.ql.metadata.HiveException: Unable to rename output from: hdfs://nameservice/user/hive/warehouse/om_dw.
715 0
|
Web App开发 前端开发 大数据
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
提  纲     1、移动DSP与传统营销有什么不同?     2、为什么移动DSP是大势所趋?     3、哪些因素决定移动DSP的精准与否?     4、如何辨别移动DSP的真伪优劣?     ...
928 0
|
Web App开发 前端开发 算法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
大数据风控指标介绍 2016-03-24 大林 1查准率与查全率 先说个例子,申请人有400个,其中有160个是好人,240个是坏人。
672 0