如何为UIButton着色? [英] How to tint a UIButton?

查看:120
本文介绍了如何为UIButton着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的iPhone用户界面添加自定义按钮,并希望让它们具有Apple应用程序的玻璃外观。我有一个很好的默认玻璃图像,但我不想为我想要的每种色调(红色,绿色,蓝色等)都有一个单独的图像。

I'm in the process of adding custom buttons to my iPhone UI and want to make them have the glassy look from Apple's apps. I have a good default glass image, but I'd hate to have to have a separate image for each tint I want (red, green, blue, etc.).

有没有办法加载灰度PNG并将其调整为我想要的颜色?更好的是,有没有办法让Apple的玻璃外观完全不需要加载自定义图像?

Is there a way to load a grayscale PNG and adjust it to the color I want? Better yet, is there a way to get Apple's glassy look without having to load custom images at all?

推荐答案

没有我所知道的一种单行方式,但您可以通过获取默认灰度图像并将其合成(即在其上绘制)纯色来获得所需的效果。如果您查看Core Graphics文档,可以看到有十几种不同的合成方法(例如,Color Burn),它们的某些组合可能会产生您想要的效果。

There isn't a one-liner way that I know of, but you might be able to get the desired effect by taking the default grayscale image and compositing it with (i.e. drawing it on top of) a solid color. If you look through the Core Graphics documentation, you can see there are over a dozen different compositing methods (e.g., Color Burn), and some combination of them may produce the effect you want.

这篇关于如何为UIButton着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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