Round corners on UITableView

前端 未结 8 659
野的像风
野的像风 2020-11-28 06:13

What is the best way to get round corners on an entire UITableView as seen in Stocks and Spotlight? The grouped style doesn\'t solve the problem because the round corners sc

相关标签:
8条回答
  • 2020-11-28 06:37

    Well, there is alot of approach to solve this problem.

    However, in my case, all doesn't work correctly. My table sometimes is smaller than table size.

    I will share the way I did. I belive is alot easer and faster than some options above.

    Make the first and last item rounded.

    • Create CAShapeLayer for top(left|right) and bottom(left|right).

      shapeTop = [CAShapeLayer layer];
      shapeTop.path = [UIBezierPath 
      bezierPathWithRoundedRect:CGRectMake( 0.0f, 0.0f, 306.0f, 58.0f )
      byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
      cornerRadii:CGSizeMake( 6.0f, 6.0f )].CGPath;
      
      shapeBottom = [CAShapeLayer layer];
      shapeBottom.path = [UIBezierPath 
      bezierPathWithRoundedRect:CGRectMake( 0.0f, 0.0f, 306.0f, 58.0f )
      byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
      cornerRadii:CGSizeMake( 6.0f, 6.0f )].CGPath;
      
    • The table need to be backgroud clearColor;

    • The cells has to be a colored background;
    • Set the layer.mask of it

      UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
      backgroundView.backgroundColor = [UIColor whiteColor];
      cell.backgroundView = backgroundView;
      
    • Don't forget #import <QuartzCore/QuartzCore.h>

    0 讨论(0)
  • 2020-11-28 06:37

    I recently came across this problem and solved it a different way. Thought I'd share the results with everyone.

    I created a rectangular UIView with a clear, rounded-corner interior, and then laid that on top of the UITableView. You can find the full description at my programming blog.

    It works exactly the way I want.

    0 讨论(0)
提交回复
热议问题