为uitableview创build边框

我在uiview中使用uitableview和scrollview。 如何设置表格或滚动视图的边框?

#import "QuartzCore/QuartzCore.h" 

然后在viewDidLoad使用,

 tableView.layer.borderWidth = 2.0; 

注意

您还可以设置边框颜色:

 tableView.layer.borderColor = [UIColor redColor].CGColor; 

它应该为你工作。 🙂

这对我来说很好:

 CALayer *layer = _tableView.layer; [layer setMasksToBounds:YES]; [layer setCornerRadius: 4.0]; [layer setBorderWidth:1.0]; [layer setBorderColor:[[UIColor colorWithWhite: 0.8 alpha: 1.0] CGColor]]; 

圆形的边框看起来更多一点的iOS。

如果你想给边框颜色的tableview,使用下面的代码swift 3

 yourTableViewName.layer.borderColor = UIColor.gray.cgColor yourTableViewName.layer.borderWidth = 1.0