绘图背景颜色 &边框与背景 PNG [英] Drawing backgroundcolor & border Vs Background PNGs
问题描述
我的 iPad 应用程序的大多数按钮都需要特定的 RGB 十六进制颜色.
I want specific RGB hex color for most of the buttons for my iPad Application.
我所做的是:我已经在我的项目中实现了 UIButton
子类,它模拟了所需的背景颜色、文本颜色和按钮边框 - 然后我在项目中需要 UIButton
的任何地方使用它.
What I have done is:
I have implemented UIButton
Subclass in my project which emulates the required background color, text color & border for buttons - and then I use it everywhere in my project where I need UIButton
.
我的 UI/UX 设计师不提供 PNG,而是坚持要求我模仿具有十六进制代码的相同颜色的网站按钮.我更像是一个背景 PNG 粉丝.
My UI/UX designer do not provide PNGs instead he insist that I imitate the same color web site buttons are having with Hex codes. I am more of a background PNGs fan.
现在,您可能想知道这个问题与编程的关系是,我正在访问 .layer.borderWidth
&.layer.borderColor
子类中的属性,最终会在任何地方使用.
Now, relation of this question to programming as you might wonder is that, I am accessing .layer.borderWidth
& .layer.borderColor
property in Subclass which eventually gets used everywhere.
那么,这种方法比使用背景 PNG 对应用程序有好处吗?
So, is this approach doing any good to the Application instead of using background PNGs?
注意 (如果相关):所有按钮的大小相同.
Note (if relevant): All the buttons are of same size.
推荐答案
你可以自己从颜色制作UIImage并设置你的Button图片:
you can make UIImage from color by yourself and set yourButton image:
+ (UIImage *)imageFromColor:(UIColor *)color {
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
这篇关于绘图背景颜色 &边框与背景 PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!