ios 你如何在 UITableViewCell 的 contentView 周围放置边框?(用于检测)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7682520/
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
How do you put a border around a UITableViewCell's contentView? (for testing)
提问by Greg
what's the code to put a border around a UITableViewCell's contentView? (for testing)
在 UITableViewCell 的 contentView 周围放置边框的代码是什么?(用于检测)
If not possible why is this? (for my learning)
如果不可能,这是为什么?(为了我的学习)
回答by Stuart
Have you tried using contentView
's underlying CALayer
? Try something like this:
你有没有试过使用contentView
的基础CALayer
?尝试这样的事情:
#import <QuartzCore/QuartzCore.h>
- (void)someAppropriateMethod
{
[self.myTableViewCell.contentView.layer setBorderColor:[UIColor redColor].CGColor];
[self.myTableViewCell.contentView.layer setBorderWidth:1.0f];
}
回答by chown
You could also apply it to the cells contentView loke so:
您还可以将其应用于单元格 contentView loke,因此:
#import <QuartzCore/QuartzCore.h>
- (void)someAppropriateMethod {
? ? myTableViewCell.contentView.layer.borderColor = [[UIColor redColor] CGColor];
? ? myTableViewCell.contentView.layer.borderWidth = 1;
}
回答by Ahmed Khedr
Swift 4:
斯威夫特 4:
myTableViewCell.contentView.layer.borderColor = UIColor.black.cgColor
myTableViewCell.contentView.layer.borderWidth = 1.0
回答by tania_S
#import <QuartzCore/QuartzCore.h>
- (void)someAppropriateMethod {
myTableViewCell.contentView.layer.borderColor = [[UIColor redColor] CGColor];
myTableViewCell.contentView.layer.borderWidth = 1;
}