iOS学习应用开发就业课_005:UIView对象

难点:

1.UIView的继承和隐藏;

2.UIView的层级关系;

3.创建3个UIView,1个为父视图,2个为子视图,设置他们的显示关系;


复习次数:3次

5月13日

5月16日

5月31日



源代码:

- (void)viewDidLoad {

    [super viewDidLoad];

    UIView *vc=[[UIView alloc ]initWithFrame:CGRectMake(10, 10, 100, 200)];

    vc.backgroundColor=[UIColor yellowColor];

    vc.tag=101;

    [self.view addSubview:vc];

    

    UIView *vc2=[[UIView alloc ]initWithFrame:CGRectMake(0, 0, 50, 50)];

    vc2.backgroundColor=[UIColor redColor];

    vc2.tag=102;

    [vc addSubview:vc2];

    

    UIView *vc3=[[UIView alloc ]initWithFrame:CGRectMake(50, 50, 50, 50)];

    vc3.backgroundColor=[UIColor blackColor];

    vc3.tag=103;

    [vc addSubview:vc3];

    

    UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn.frame=CGRectMake(50, 250, 80, 40);

    [btn setTitle:@"隐藏视图3" forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

}

-(void)hide

{

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

    hideView=[self.view viewWithTag:103];

    hideView.hidden=YES;

    

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

    hideView2=[self.view viewWithTag:102];

    hideView2.alpha=0.5;


    

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值