问题描述
我一直在寻找改善iPhone应用程序整体吸引力的方法.大多数功能发生在UITATIONVIEW中.我想我可以从将微妙的梯度添加到UitaiteViewCells中,因为这似乎可以通过数量级来改善应用程序的感觉.选择适当的字体/尺寸也有助于大大帮助.我对这个论坛的问题是,将梯度添加到UitableViewCells中的最佳策略是什么?您使用的是核心图形/石英吗?您是否使用1x1像素图像并拉伸它?我在tumblr iPhone应用程序的以下屏幕截图中很有趣: http://dl-client.getdropbox.com/u/57676/screenshots/tumblr.jpg
有人有任何很好的例子说明如何使您的UitableViewCell伸出来吗?
出于性能原因,使用石英使用图像或绘制更好?如果石英,我很想看到一些人如何将梯度绘制到细胞中的示例代码.
谢谢.
推荐答案
我在Tumblr工作,虽然我没有编写iPhone应用程序(他做到了),我有来源,可以告诉您它是如何完成的.
in -tableView:cellForRowAtIndexPath:
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"postCellBackground.png"]]; cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"postCellBackgroundSelected.png"]];
非常简单,实际上:uiimageview中的png图像作为单元格的背景视图.
这两个图像是1x61垂直梯度,Uikit自动伸展以适合细胞的宽度.
其他推荐答案
在iPhone SDK 3.0时,有一个更简单的解决方案依赖于新的Cagradientlayer,并且不需要子分类或图像.
其他推荐答案
Marco的答案非常适合普通的表观视图单元格和位于表观中间的分组表视图单元格,但是如果您尝试在分组中设置第一个/最后一个单元格的背景视图桌子然后将打破圆角.要修复它
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Gradient.png"]];
问题描述
I've been looking for ways to improve the overall attractiveness of my iPhone applications. A majority of the functionality happens in UITableView. I think I can start by adding subtle gradients to UITableViewCells, as that seems to improve the feel of the app by an order of magnitude. Selecting the appropriate fonts/sizes helps a great deal also. My question for this forum is, what's the best strategy of adding gradients to UITableViewCells? Are you using Core Graphics/Quartz? Are you using a 1x1 pixel image and stretching it? I'm interesting in something along the lines of the following screenshot of the Tumblr iPhone app: http://dl-client.getdropbox.com/u/57676/screenshots/tumblr.jpg
Does anyone have any good examples of how to make your UITableViewCell's stick out?
And for performance reasons is it better to use an image or draw with Quartz? If Quartz, I'd love to see some sample codes of how folks are drawing the gradients into the cells.
Thanks.
推荐答案
I work for Tumblr, and while I didn't write the iPhone app (he did), I have the source and can tell you how it's done.
In -tableView:cellForRowAtIndexPath:
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"postCellBackground.png"]]; cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"postCellBackgroundSelected.png"]];
Pretty simple, really: PNG images in a UIImageView as the cell's background views.
The two images are 1x61 vertical gradients that UIKit automatically stretches horizontally to fit the width of the cell.
其他推荐答案
As of iPhone SDK 3.0, there's a much simpler solution that relies on the new CAGradientLayer and doesn't require subclassing or images.
其他推荐答案
Marco's answer works great for plain table view cells and for grouped table view cells that are located in the middle of the table view, but if you try to set a background view for the first/last cell in a grouped table then it will break the rounded corners. To fix it you can set cell background color to a UIColor colorWithPatternImage, e.g:
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Gradient.png"]];