UIView中的圆角

时间:2012-10-04 14:27:26

标签: objective-c ios core-graphics

我有一个UIView,我想围绕它并添加阴影颜色,如下图所示:image rounded

2 个答案:

答案 0 :(得分:2)

对于Rounder Corner

 CAShapeLayer * maskLayer = [CAShapeLayer layer];
    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerTopRight cornerRadii: (CGSize){10.0, 10.}].CGPath;

    self.layer.mask = maskLayer;

For Shadow

self.layer.masksToBounds = NO;
self.layer.shadowOffset = CGSizeMake(-15, 20);
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = 0.5;

希望这能帮到你!

答案 1 :(得分:0)

要获得与图像完全相同的阴影,我建议您使用背景图像。否则,您应该包含<Quartzcore/Quartzcore.h>并使用以下代码:

view.layer.cornerRadius = 10;
view.frame = CGRectMake(15, 15, 100, 100);
view.backgroundColor = [UIColor redColor];
view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOffset = CGSizeMake(2.0, 2.0);
view.layer.shadowOpacity = 0.8;
view.layer.shadowRadius = 10;

有关背景图片选项的更多信息

创建一个与包含阴影的图像具有相同宽度和高度的UIView,并以这种方式将图像分配给它:

view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundview.png"]];