UIView

   //1.UIView创建和使用

    //  重要性:

    //  (1) 常见控件父类或间接父类都是UIView

    //UILabel->UIView

    //UIImageView->UIView

    //UIButton->UIControl->UIView

    //  (2)自定义控件

    //  继承与UIView, view加上其他控件

    //  (3)使用UIView作为界面布局, UIView作为其他控件的容器

    //理解: 显示一块矩形区域

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

    view1.frame = CGRectMake(100, 100, 100, 100);

    view1.backgroundColor = [UIColor redColor];

    [self.view addSubview:view1];

    

    //2.常用属性

    //位置

    //view1.frame

    //只改大小, 不改位置

    view1.bounds = CGRectMake(0, 0, 50, 50);

    view1.backgroundColor = [UIColor yellowColor];

    

    //使用tag区分不同控件

    //view1.tag = 100;

    

    //设置中心点位置

    view1.center = CGPointMake(50, 50);

    

    //是否打开用户交互

    //UILabelUIImageView控件这个值是NO

    //  按钮加入到UIImageView没有反应

    view1.userInteractionEnabled = YES;

    

    //view设置圆角

    view1.layer.cornerRadius = 10;

    view1.clipsToBounds = YES;

    

    //是否隐藏

    view1.hidden = YES;

    view1.hidden = NO;

    

    //透明度

    view1.alpha = 0.7;

    

    //3.常用方法

    //view1 addSubview:<#(UIView *)#>

    //界面上移除控件

    //[view1 removeFromSuperview];

    

    //视图层级关系方法

    view1.frame = CGRectMake(100, 100, 100, 100);

    

    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];

    view2.backgroundColor = [UIColor blueColor];

    [self.view addSubview:view2];

    

    //放到最前面

    [self.view bringSubviewToFront:view1];

    

    //最后面

    [self.view sendSubviewToBack:view1];

    

    //插入视图

    UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(125, 125, 100, 100)];

    view3.backgroundColor = [UIColor greenColor];

    //[self.view addSubview:view3];

    [self.view insertSubview:view3 belowSubview:view2];

    

    //属性

    //所有子视图

    //self.view.subviews

    

    //父视图

    //self.view.superview

    

    //4.使用UIView进行控件自定义和界面布局

    //  view+2label+一个图片

    //原理: 只是原理展示, 控件定制需要继承

    UIView *photoView = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 320, 100)];

    photoView.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:photoView];

    

    //头像

    UIImageView *headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 60, 60)];

    headImageView.image = [UIImage imageNamed:@"defaultHead.png"];

    [photoView addSubview:headImageView];

    

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, 100, 30)];

    label.text = @"风景";

    [photoView addSubview:label];

    

    

    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 60, 100, 30)];

    timeLabel.text = @"2014-08-26";

    [photoView addSubview:timeLabel];

    

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dealTap)];

    [photoView addGestureRecognizer:tap];

    

    //5.UIView的动画(扩展: 仿射变换)

    UIImageView *bullet = [[UIImageView alloc] initWithFrame:CGRectMake(10, 450, 20, 20)];

    bullet.image = [UIImage imageNamed:@"bullet.png"];

    [self.view addSubview:bullet];


//    [UIView animateWithDuration:2 animations:^{

//        bullet.frame = CGRectMake(300, 450, 50, 50);

//        bullet.alpha = 0;

//    }];

    

    //

    [UIView animateWithDuration:4 delay:0 options:UIViewAnimationOptionAutoreverse animations:^{

        bullet.frame = CGRectMake(300, 450, 50, 50);

        //bullet.alpha = 0;

    } completion:^(BOOL finished) {

        [bullet removeFromSuperview];

    }];

    

}

-(void)dealTap

{

    NSLog(@"点击相册");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值