使用渐变背景设计UITableViewCells [英] Styling UITableViewCells with gradient backgrounds

查看:275
本文介绍了使用渐变背景设计UITableViewCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找提高iPhone应用程序整体吸引力的方法。大部分功能发生在UITableView中。我想我可以通过在UITableViewCells中添加微妙的渐变开始,因为这似乎提高了应用程序的感觉一个数量级。选择适当的字体/大小也有很大的帮助。我的这个论坛的问题是,添加渐变到UITableViewCells的最佳策略是什么?您是否使用Core Graphics / Quartz?您是否使用1x1像素图像并展开它?我在Tumblr iPhone应用程序的以下屏幕截图中有所帮助: http://dl-client.getdropbox.com/u/57676/screenshots/tumblr.jpg



有没有人有什么好的例子为了让你的UITableViewCell伸出手来?



出于性能原因,最好使用图形或使用Quartz绘图?如果是Quartz,我希望看到一些示例代码,让人们将渐变绘制到单元格中。



谢谢。

解决方案

我为Tumblr工作,虽然我没有写iPhone应用程序(他做了),我有源码,可以告诉你如何完成。



-tableView:cellForRowAtIndexPath: code>

  cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@postCellBackground.png ]]; 
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@postCellBackgroundSelected.png]];

很简单,真的:在UIImageView中的PNG图像作为单元格的背景视图。



两个图像是1x61垂直渐变,UIKit自动水平延伸以适应单元格的宽度。


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.

这篇关于使用渐变背景设计UITableViewCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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