Uiview的简单使用

layoutSubviews、layoutIfNeeded、setNeedsLayout...
  • UIView的几个layout方法
毛玻璃效果
//创建图片
    self.view.backgroundColor = [UIColor blackColor];
    self.blurImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
    [self.blurImageView sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1498707379&di=a924ec5370156b954c80b44b0324d8e1&imgtype=jpg&er=1&src=http%3A%2F%2Fpic.ffpic.com%2Ffiles%2F2014%2F0531%2F0530xgmycmnsjbz2.jpg"] placeholderImage:[UIImage imageNamed:@"default_room"]];
    self.blurImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.blurImageView.clipsToBounds = true;
    [self.view addSubview:self.blurImageView];
    //毛玻璃效果
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    //创建毛玻璃视图
    UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithEffect:blur];
    visualView.frame = self.blurImageView.bounds;
    [self.blurImageView addSubview:visualView];
添加到window
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
 view.backgroundColor = [UIColor blackColor];
 view.alpha = 0.5;
  [[UIApplication sharedApplication].keyWindow addSubview:view];
视图移到最前和最后

将一个UIView显示在最前面只需要调用其父视图的 bringSubviewToFront()方法。
将一个UIView层推送到背后只需要调用其父视图的 sendSubviewToBack()方法。

移除指定视图
//创建时要指定tag值
self.guideView = [[UIView alloc]init];
self.guideView.tag = 120;
//移除
UIView *subview = [self.guideView viewWithTag:120];
[subview removeFromSuperview];

勤学如早春之苗,不见其增,日有所涨。
辍学如磨刀之石,不见其减,日有所损。

你可能感兴趣的:(Uiview的简单使用)