码迷,mamicode.com
首页 > 其他好文 > 详细

初识UI

时间:2015-04-16 12:29:26      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:uiview   window   uicolor   cgrect   cgpoint   

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

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

    self.window = window;

    window.backgroundColor = [UIColor grayColor];

    [self.window makeKeyAndVisible];

    CGRect rect = self.window.frame;

    NSLog(@"%@",NSStringFromCGRect(rect));// 获取当前window尺寸

    

    // 1. 创建一个视图并且显示到window

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

    view.frame = CGRectMake(200, 100, 100, 190);// 控制当前视图的位置宽高

    view.backgroundColor = [UIColor greenColor];// 设置子控件的颜色

    

    [self.window addSubview:view];// 添加子控件到父视图

    // 子视图frame

    NSLog(@"%@",NSStringFromCGRect(view.frame));

    // 子视图bounds

    NSLog(@"%@",NSStringFromCGRect(view.bounds));

    // 子视图中心

    NSLog(@"%@",NSStringFromCGPoint(view.center));

    


// 创建myView

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

    CGRect  myRect = CGRectMake(120, 220, 30, 40);

    myView.frame = myRect;

    myView.backgroundColor = [UIColor brownColor];

    [self.window addSubview:myView];

// 创建mySecondView    

    UIView * mySecondView = [[UIView alloc]initWithFrame:CGRectMake(100, 200, 290, 40)];

    mySecondView.backgroundColor = [UIColor purpleColor];

    [self.window addSubview:mySecondView];

    UIView,window,UIColor,CGRect,CGPoint,oc    

// 创建myThirdView

    // 视图插入到当前的索引位置

    UIView * myThirdView = [[UIView alloc]initWithFrame:CGRectMake(150, 170, 90, 40)];

    myThirdView.backgroundColor = [UIColor cyanColor];

    UIView,window,UIColor,CGRect,CGPoint,oc    

    [self.window insertSubview:myThirdView atIndex:2];// 将视图插入到下标的位置

    [self.window insertSubview:myView aboveSubview:myThirdView];// 将视图myView移到myThirdView之上

    [self.window bringSubviewToFront:view];// 将视图view移到最上面

UIView,window,UIColor,CGRect,CGPoint,oc    

    [self.window sendSubviewToBack:myView];// 将视图view移到最下面

    UIView,window,UIColor,CGRect,CGPoint,oc    

    [self.window exchangeSubviewAtIndex:2 withSubviewAtIndex:0];// 将两位视图的下标交换,来交换两个视图的位置

    [view removeFromSuperview]; // 将子视图从父视图中删除掉

    UIView,window,UIColor,CGRect,CGPoint,oc    

UIView,window,UIColor,CGRect,CGPoint,oc    

    return YES;

}

初识UI

标签:uiview   window   uicolor   cgrect   cgpoint   

原文地址:http://blog.csdn.net/zx6268476/article/details/45072505

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!