ios 为 uitableview 创建边框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4283041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
creating border for uitableview
提问by ravoorinandan
I am using a uitableview and scrollview in a uiview. How to set a border for table or scrollview?
我在 uiview 中使用 uitableview 和 scrollview。如何为表格或滚动视图设置边框?
回答by Naveen Thunga
#import "QuartzCore/QuartzCore.h"
then in viewDidLoad
use,
然后在viewDidLoad
使用中,
tableView.layer.borderWidth = 2.0;
Note
笔记
You can also set the border color:
您还可以设置边框颜色:
tableView.layer.borderColor = [UIColor redColor].CGColor;
It should work for you. :)
它应该适合你。:)
回答by Oliver
This works quite well for me:
这对我来说非常有效:
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]];
The rounded borders look a little more iOS.
圆形边框看起来更像 iOS。
回答by Kiran jadhav
if you want to give the border to tableview with color, use below code for swift 3
如果您想为带有颜色的 tableview 提供边框,请使用下面的代码进行 swift 3
yourTableViewName.layer.borderColor = UIColor.gray.cgColor
yourTableViewName.layer.borderWidth = 1.0