围绕矩形的边发光

时间:2013-06-13 15:54:20

标签: iphone ios6 uiview core-graphics

我正在尝试在矩形的两侧创建发光。矩形的其余部分应填充清晰的颜色。我创建了一个UIView CGRect的特定大小,然后 -

    self.backgroundColor = [UIColor clearColor];

    self.layer.borderWidth = 2.0f;
    self.layer.borderColor = [UIColor colorWithRed:203/255.0 green:1.0 blue:252/255.0 alpha:1.0f].CGColor;
    self.layer.cornerRadius = 5.0f;
    int glowSpread = 2;
    CGRect glowRect = CGRectMake(self.bounds.origin.x-glowSpread, self.bounds.origin.y-glowSpread, self.bounds.size.width+2*glowSpread, self.bounds.size.height+2*glowSpread);
    self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:glowRect cornerRadius:5.0].CGPath;
    self.layer.shadowColor = [UIColor colorWithRed:203/255.0 green:1.0 blue:252/255.0 alpha:1.0f].CGColor;
    self.layer.shadowOffset = CGSizeMake(0, 0);
    self.layer.shadowOpacity = 0.5;
    self.layer.shadowRadius = 2.0f;

通过上述方法,我得到了侧面的光晕,但整个CGRect充满了阴影颜色,这是我不想要的。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

制作一个未包含的更复杂的阴影路径,或者只添加所需颜色的子图层。