我用 UIBezierpath 创建了一个圆角矩形,这对我很有用。只有一个问题是矩形的圆边有一种锯齿效应。这是一张图片
我像这样创建圆角矩形:
CGFloat radius = 12;
CGRect frame1 = CGRectMake(self.bounds.origin.x, self.bounds.origin.y+(self.bounds.size.height/heightFactor), self.bounds.size.width-shadowConst, self.bounds.size.height-(self.bounds.size.height/heightFactor)-shadowConst);
CGRect frame2 = CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor), self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2)), (self.bounds.size.width/widthFactor)-shadowConst, (self.bounds.size.height/heightFactor));
UIBezierPath *result =
[UIBezierPath bezierPathWithRoundedRect: frame1 cornerRadius:radius];
[result appendPath:
[UIBezierPath bezierPathWithRoundedRect: frame2 cornerRadius:radius]];
[result fill];
[result addClip];
CGContextDrawLinearGradient(context, gradient2, CGPointMake(0, 0), CGPointMake(0, self.bounds.size.height), 0);