1

我正在尝试在矩形的两侧创建发光。矩形的其余部分应填充清晰的颜色。我创建了一个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都充满了阴影颜色,这是我不想要的。有什么建议吗?

4

1 回答 1

0

制作一个不封闭的更复杂的阴影路径,或者只是添加您想要的颜色的子层。

于 2013-06-13T19:15:27.273 回答