ui问题iOS-UI

iOS 视图控件设置圆角、阴影

2017-08-22  本文已影响167人  FlowYourHeart
上下两种不同处理方式
 //imageView的superView
    UIView *fangkuanView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
    //imageView的superView 的阴影view
    UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 300, 200)];//这里的大小将不影响fangkuanView1 的显示(即这里只起 设置frame.origin的作用)
    //阴影设置
    shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
    shadowView.layer.shadowOffset = CGSizeMake(4, 4);
    shadowView.layer.shadowOpacity = 0.5;
    shadowView.layer.shadowRadius = 4.0;
    shadowView.layer.cornerRadius = 10.0;
    
    //superView
    fangkuanView1.layer.masksToBounds = YES;
    fangkuanView1.layer.cornerRadius = 10;
    fangkuanView1.clipsToBounds = YES;
    fangkuanView1.backgroundColor = [UIColor whiteColor];
    //imageView
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
    imageView.image = [UIImage imageNamed:@"atop"];
    
    [fangkuanView1 addSubview:imageView];
    [shadowView addSubview:fangkuanView1];
    [self.view addSubview:shadowView];

下面两个圆角的设定


//设置任意角为圆角
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 400, 80, 80)];
    view2.backgroundColor = [UIColor redColor];
    [self.view addSubview:view2];
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = view2.bounds;
    maskLayer.path = maskPath.CGPath;
    view2.layer.mask = maskLayer;
上一篇下一篇

猜你喜欢

热点阅读