Bạn có thể làm điều đó với đoạn này:
// Set top right & left corners
[self setMaskTo:yourView byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
EDIT
Xin lỗi, tôi quên
- (void)setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners
{
UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(8.0, 8.0)];
CAShapeLayer *shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
view.layer.mask = shape;
}
PS này: như tôi đã nói trong các bình luận, nếu bạn sử dụng những thứ như thế này khi hiển thị UITableViewCell
ô, tôi đã cho und rằng nó luôn luôn là một lựa chọn tốt hơn để sử dụng hình ảnh nền bởi vì loại công cụ vẽ luôn luôn ảnh hưởng đến hiệu suất.
http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview?rq=1 –
thể trùng lặp của [cách thiết cornerRadius chỉ trên bên trái và đỉnh góc phải của một UIView?] (http://stackoverflow.com/questions/10167266/how-to-set-cornerradius-for-only-top-left-and-top-right-corner-of-a-uiview) –