当前位置: 移动技术网 > IT编程>移动开发>IOS > ios学习第五天(二)给页面中的View添加子View

ios学习第五天(二)给页面中的View添加子View

2018年09月22日  | 移动技术网IT编程  | 我要评论

英尼格玛,000527最新消息,广州性文化节2014

ios学习第五天(二)给页面中的view添加子view,上一篇文章已经对ios页面进行了说明,接下来就是使用页面,给页面中添加子控件,在上面两篇创建的项目中,进行些许修改,成了现在的。先看效果:

效果:

\

代码:

修改viewcontroller

//
//  viewcontroller.m
//  helloios
//
//  created by moluth on 17/4/10.
//  copyright (c) 2017年 moluth. all rights reserved.
//

#import "viewcontroller.h"

@interface viewcontroller ()

@end

@implementation viewcontroller

- (void)viewdidload {
    [super viewdidload];
    self.view.backgroundcolor=[[uicolor alloc] initwithred:0.3f green:0.35f blue:0.85f alpha:1.0f];
    
    uiview *view1=[[uiview alloc] initwithframe:cgrectmake(0, 0, 100, 100)]//创建view ,view是矩形,0,0表示左上角坐标,后面的100,100代表宽高
    view1.backgroundcolor=[[uicolor alloc] initwithred:0.88f green:0.66f blue:0.11f alpha:0.8f];//给新创建的view设置背景颜色,便于观察
    [self.view addsubview:view1];//向viewcontroller中的view中添加子view
    
    //下面代码都是对上面的复制和修改,仅仅是坐标和颜色不同
    uiview *view2=[[uiview alloc] initwithframe:cgrectmake(30, 30, 100, 100)];
    view2.backgroundcolor=[[uicolor alloc] initwithred:1.0f green:0.0f blue:0.6f alpha:0.8f];
    [self.view addsubview:view2];
    
    uiview *view3=[[uiview alloc] initwithframe:cgrectmake(60, 60, 100, 100)];
    view3.backgroundcolor=[[uicolor alloc] initwithred:1.0f green:1.0f blue:0.6f alpha:0.8f];
    [self.view addsubview:view3];
    
    uiview *view4=[[uiview alloc] initwithframe:cgrectmake(90, 90, 100, 100)];
    view4.backgroundcolor=[[uicolor alloc] initwithred:0.0f green:1.0f blue:0.0f alpha:0.8f];
    [self.view addsubview:view4];
    
    
    //self.view
    
    // do any additional setup after loading the view, typically from a nib.
}

- (void)didreceivememorywarning {
    [super didreceivememorywarning];
    // dispose of any resources that can be recreated.
}

@end

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网