UITableView上的圆角 [英] Round corners on UITableView

查看:190
本文介绍了UITableView上的圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Stocks和Spotlight中看到的整个UITableView上获得圆角的最佳方法是什么?分组的样式不能解决问题,因为圆角会随着单元格滚动。我正在尝试剪切视图,因此不管滚动位置如何,角都是圆的。

What is the best way to get round corners on an entire UITableView as seen in Stocks and Spotlight? The grouped style doesn't solve the problem because the round corners scroll away with the cell. I'm trying to clip the view so the corners are always round regardless of scroll position.

我看到另一个关于对UIImage做这个的讨论,建议用另一个图像掩盖它。我不确定这是否有效,因为我需要点击才能传递到桌面。这对我来说并不理想,因为我希望通过角落显示背景图案。

I saw another discussion about doing this to a UIImage that suggested masking it with another image. I'm not sure if this would work because I need taps to pass through to the table. This isn't isn't ideal for me because I want the background pattern to show through through the corners.

推荐答案

这是一个老问题,但也许您仍然想知道如何做到这一点。

It's an old question but perhaps you still want to know how to do this.

我在Stocks / Spotlight中复制了一个tableView。诀窍是

I reproduced a tableView like in Stocks/Spotlight. The trick is

view.layer.cornerRadius = 10; 

为此,您需要将QuartzCore包含在您调用该属性的类中:

For this to work you need to include the QuartzCore into the class that you call that property:

#import <QuartzCore/QuartzCore.h>

我听说这只适用于OS 3.0。但由于我的应用程序使用的是核心数据,因此它已经适用于OS 3.0和hight。

I heard that this only works since OS 3.0. But since my application is using core data it wasn't a problem because it was already for OS 3.0 and hight.

我创建了一个带有cornerRadius 10子视图的自定义UIView和

I created a custom UIView with a subview with cornerRadius 10 and with

view.backgroundColor = [UIColor clearColor];

然后你必须在该子视图中放置一个UITableView分组样式。您需要将backgroundColor设置为clearColor,将separatorColor设置为clearColor。然后,您必须将tableview放置在圆角视图内,这可以通过设置框架大小和原点来完成。我的自定义UIView的loadView类看起来像这样:

Then you have to place an UITableView grouped style in that subview. You need to set the backgroundColor to clearColor and the separatorColor to clearColor. Then you have to position the tableview inside the rounded corner view, this is done by setting the frame size and origin. My loadView class of my custom UIView looks like this:

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];

我希望你能理解我的英文,也许我会写一篇关于这个技巧的短文博客文章项目,我准备好后会在这里发布链接。

I hope you understand my english, maybe I will write a short blog post about this technique with a sample project, will post the link here when I'm ready.

这篇关于UITableView上的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆