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

查看:58
本文介绍了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 和高版本.

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和

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天全站免登陆