什么是在股票和Spotlight中看到的整个UITableView的圆角的最佳方式?分组样式不能解决问题,因为圆角与单元格一起滚动。我试图剪辑视图,因此无论滚动位置如何,角落都是圆形的。UITableView的圆角
我看到了另一个关于如何对UIImage进行的讨论,该UIImage建议使用另一个图像来掩盖它。我不确定这是否会起作用,因为我需要点击才能通过表格。这对我来说并不理想,因为我希望背景图案能够透过角落展现出来。
什么是在股票和Spotlight中看到的整个UITableView的圆角的最佳方式?分组样式不能解决问题,因为圆角与单元格一起滚动。我试图剪辑视图,因此无论滚动位置如何,角落都是圆形的。UITableView的圆角
我看到了另一个关于如何对UIImage进行的讨论,该UIImage建议使用另一个图像来掩盖它。我不确定这是否会起作用,因为我需要点击才能通过表格。这对我来说并不理想,因为我希望背景图案能够透过角落展现出来。
您是否尝试过“分组”表格视图样式?
self.tableView.style = UITableViewStyleGrouped;
如需进一步参考,请参阅Table View Programming Guide。 “关于表视图”一章有一些很好的截图,描述了不同的风格。
当你向上滚动表格时,它会用圆角掩盖它,我想这就是他所指的。虽然这将是一个很好的开始,我猜,并使背景透明。 – Garrett 2009-07-09 23:11:31
是的,这听起来像你在这个正确的轨道上。 – 2009-07-09 23:12:19
@Garrett:哦..刚开始我的股票应用程序,看看你的意思。直到现在真的没有注意到这种效果..;-)对不起,我认为他指的是简单的分组表格视图。 – 2009-07-09 23:14:43
另一种方法是使用Core Graphics来掩盖UITableView。掩盖UIView的一个例子可以在这里找到: http://iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html
这帮助了很多,但它不会在单元格滚动通过UITableView本身的剪切区域时剪切单元格。 – Scrollwheelie 2009-07-12 08:00:37
这是一个古老的问题,但也许你仍然想知道如何做到这一点。
我转载了一个像股票/聚光灯一样的tableView。诀窍是
view.layer.cornerRadius = 10;
对于这个工作,你需要将QuartzCore包括到您调用属性的类:
#import <QuartzCore/QuartzCore.h>
听说因为OS 3.0这仅适用。但是由于我的应用程序正在使用核心数据,所以它不是问题,因为它已经用于OS 3.0和Hight。
我创建了一个自定义的UIView有一个子视图与cornerRadius 10与
view.backgroundColor = [UIColor clearColor];
然后你必须把一个分组的UITableView风格在子视图。您需要将backgroundColor设置为clearColor,将separatorColor设置为clearColor。然后,您必须将桌面视图放置在圆角视图内,这是通过设置框架大小和原点来完成的。我的loadView类我自定义的UIView是这样的:
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor clearColor];
CustomUIViewClass *scherm = [[CustomUIViewClass alloc] init];
CGRect frame;
frame.origin.x = 10;
frame.origin.y = 50;
frame.size.width = 300;
frame.size.height = 380;
scherm.frame = frame;
scherm.clipsToBounds = YES;
scherm.layer.cornerRadius = 10;
[self.view addSubview:scherm];
CustomUITableViewClass *table = [[CustomUITableViewClass alloc] initWithStyle:UITableViewStyleGrouped];
frame.origin.y = -10;
frame.origin.x = -10;
frame.size.width = 320;
frame.size.height = 400;
table.tableView.frame = frame;
[scherm addSubview:table.tableView];
我希望你明白我的英语,也许我会写一个简短的博客文章关于这项技术的一个样本项目,将在这里发布的链接,当我准备。
这是我在2010年9月通过测试的各种解决方案中唯一的解决方案,它在iOS 4和iOS 3.2上非常出色,并且性能卓越。将它集成到我的应用程序中。谢谢,汉斯! – DenTheMan 2010-09-01 21:18:05
我最近遇到了这个问题,并以不同的方式解决了它。以为我会与大家分享结果。
我创建了一个带有清晰圆角内部的矩形UIView,然后将它放在UITableView的顶部。你可以在my programming blog找到完整的描述。
它的工作原理与我想要的一样。希望有所帮助。
这是我提出的解决方案。它结合了图层蒙版和图层cornerRadius。仅限iPhone OS 3.x。我没有花时间试着让滚动条工作,但我认为它不应该太困难。
更简单的方法做,这是简单地导入QuartzCore框架到您的项目。 #import <QuartzCore/QuartzCore.h>
您tableViewController和刚刚成立
myTableView.layer.cornerRadius=5;
这会给你圆润的边角,而无需你的tableview中添加到上海华盈或裁剪它。
那么,有很多方法来解决这个问题。
但是,在我的情况下,所有都不能正常工作。我的桌子有时比桌子的尺寸小。
我会分享我的做法。我相信比以上的一些选择更快捷。
使第一个和最后一个项目四舍五入。
创建顶部(左|右)和底部(左|右)的CAShapeLayer
。
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;
该表需要背景色clearColor;
设置它的layer.mask
UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
backgroundView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = backgroundView;
不要忘记#import <QuartzCore/QuartzCore.h>
而是通过代码黑客的,这里是一个简单的模仿分组风格。如果你想要的只是一个部分,这是有效的。
在界面生成器:
然后设置一些填充框架拐角半径和颜色自己:
#import <QuartzCore/QuartzCore.h>
self.tableView.layer.borderColor = [UIColor colorWithWhite:0.6 alpha:1].CGColor;
self.tableView.layer.borderWidth = 1;
self.tableView.layer.cornerRadius = 4;
下面给斯威夫特版本代码:
let redColor = UIColor.redColor()
self.tableView.layer.borderColor = redColor.colorWithAlphaComponent(0.9).CGColor
self.tableView.layer.borderWidth = 1;
self.tableView.layer.cornerRadius = 4;
确保您在导入部分有import QuartzCore
。
我不能相信这个七岁的问题仍然受到关注。我很久以前就放弃了这个功能,对不起,我自己无法测试和接受任何答案。我看到很多复选标记,谢谢大家!我很高兴看到这有帮助。 – Scrollwheelie 2016-08-24 18:24:17