2016-12-26 77 views
0

我正试图在UITableView上实现底部圆角。UITableView - 底部圆角

我用下面的代码片段,在我MyUtils.m它存在 -

/* 
* To get rounded corners of view. 
*/ 
+ (UIView *)roundCornersOnView:(UIView *)view rectCorner:(UIRectCorner)corner radius:(float)radius 
{ 
    UIView *roundedView = view; 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:roundedView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)]; 
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
    maskLayer.frame = roundedView.bounds; 
    maskLayer.path = maskPath.CGPath; 
    roundedView.layer.mask = maskLayer; 
    return roundedView; 
} 

然后我在上面MyUtils方法称为从我的快捷文件回合2次角落。一个是UIView,另一个是UITableView

override func viewDidLayoutSubviews() { 
    super.viewDidLayoutSubviews() 
     MyUtils.roundCornersOnView(myUIView, rectCorner: [.TopLeft, .TopRight], radius: 15) 
     MyUtils.roundCornersOnView(myTableView, rectCorner: [.BottomLeft, .BottomRight], radius: 15) 
} 

UIView没有问题,在UITableView情况下,我可以,我想实现的底部,但该UITableView启动后看到底部圆角滚动而不是它的内容。

通常滚动内容UITableView,但在应用此UITableView开始滚动后,可能会滚动UITableView的背景。

+0

适用clipToBounds您myTableView所以超出myTableView界限的内容将不可见。 – nferocious76

+0

@ nferocious76感谢您关注这一点,但不确定的是,这没有奏效 – Rahul

+0

可以显示我的一些截图的那部分? – nferocious76

回答

0

重写的tableView变化的其tableViewWrapper性质的掩膜层及引入了一个怪异的行为,以便为我们解决这个问题,我们需要添加一个容器视图和执行我们的屏蔽:

@interface ViewController()<UITableViewDelegate, UITableViewDataSource> 

@property (weak, nonatomic) IBOutlet UIView *container; 
@property (weak, nonatomic) IBOutlet UITableView *testTable; 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    CAShapeLayer * maskLayer = [CAShapeLayer layer]; 
    // manually configuring the mask rect will be the best way to set it rather than setting it in viewDidLayoutSubviews or viewDidAppear that can be called again when view is dismissed or popback. 
    CGRect rect = CGRectMake(0, 40, [UIScreen mainScreen].bounds.size.width - 40, [UIScreen mainScreen].bounds.size.height - 204); 

    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: rect byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){10.0, 10.}].CGPath; 

    self.container.layer.mask = maskLayer; 
    self.container.clipsToBounds = YES; 

} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return 15; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row]; 

    return cell; 
} 

@end 
+0

我们可以将UIView设置为TableView的背景视图,我们无法更新该背景视图而无需引入新的父视图吗? – Rahul

+0

编号背景每当你滚动它时,它都会改变它的偏移量,尽管你也可以手动调整它的大小,它在tableView的内容后面,所以你的角落将会在下面和无用。 – nferocious76