iPhone 上 UIView 和 UILabels 上的渐变

iPhone 上 UIView 和 UILabels 上的渐变

问题描述:

可能的重复:
在 iPhone 应用中手动绘制渐变?

我的应用程序需要在 UIViewUILabel 中显示文本,但背景必须是渐变而不是真正的 UIColor.使用图形程序来创建所需的外观并不好,因为文本可能会因服务器返回的数据而异.

My application needs to display text in either a UIView or UILabel but the back ground must be a gradient as opposed to a true UIColor. Using a graphics program to create desired look is no good as the text may vary depending on data returned from a server.

有人知道解决这个问题的最快方法吗?非常感谢您的想法.

Does anyone know the quickest way to tackle this? Your thoughts are greatly appreciated.

你也可以使用一个一像素宽的图形图像作为渐变,并设置 view 属性来扩展图形以填充视图(假设你正在考虑一个简单的线性渐变,而不是某种径向图形).

You could also use a graphic image one pixel wide as the gradient, and set the view property to expand the graphic to fill the view (assuming you are thinking of a simple linear gradient and not some kind of radial graphic).