10 replies
Sign in or join Beachball Help to reply.
- 0
Scott Squires1 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Take a look at the class ref documents.
- 0
mochasoft ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
rgb with r= 100 , g=101 and b=102:
UIColor *mycolor= [UIColor colorWithRed:100.0/255.0 green:101.0/255.0 blue:102.0/255.0 alpha:1.0]]
- 0
rab101 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Most of the time my rgb values are read from an xml document and they are specified as: 0x335bC0
for example. I will need to parse this value and convert it to r g and b values first which is really tedious.Scott,
is there a class called "ref" ?Thanks
- 0
Scott Squires1 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
refs as in reference. Every class has several pages of information and methods available.
Checking it first is a good ideaTake a look at nsstring and the scanning methods
For reading sections of text - 0
ooo27 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Seems like every one of Scott Squire's replies I come across is an RTFM comment. Ugh. I hope this is more helpful:
I had the same color creation irritation and made some simple utilities to help: If you want to make colors out of an int specified in hex such as 0x00ff00ff (rgba) you can use the following macro:
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0
green:((c>>16)&0xFF)/255.0
blue:((c>>8)&0xFF)/255.0
alpha:((c)&0xFF)/255.0];
// usage:
UIColor* c = HEXCOLOR(0xff00ffff);Then I found that CGContext<?> functions take colors as float arrays instead of using UIColors (ugh again!). So you can use this cheese here:
static float* HexToFloats(int c)
{
static float components[4];
components[0] = ((c>>24)&0xFF)/255.0;
components[1] = ((c>>16)&0xFF)/255.0;
components[2] = ((c>> 8)&0xFF)/255.0;
components[3] = ((c )&0xFF)/255.0;
return components;
}
// usage:
CGContextSetStrokeColor(c, HexToFloats(0x808080ff)); - 0
Scott Squires1 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
1. I don't have code to parse hex data nor do I have time to write it for someone.
2. If I have a clear idea of what the person wants/needs and have the code I'm fine with posting it.
In this case they actually want to take hex code data and convert into UIColor. Not the original question.
3. If you show a man to fish... in many cases there are usually answers to the questions including additional information available in the documents. Without reviewing the API or documents it's difficult for people to know which direction to go in next. - 0
rab101 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thank you very much for the examples. This is exactly what I was looking for.
Scott,
Thank you for your help and suggestions.
But just for the records, I was not asking people to write code for me.
I know how to write code to parse anything. I was hopping that someone out there was already irritated by the problem and figured it out without doing any parsing.
Also, I always check the documentation, examples etc... before asking questions. I really do believe in this, because I know that everyone out there is also busy and does not have time to go out of his way to spend it solving my problem.
The whole idea is that some one out there has already faced the same problem and is willing to share his solution, that it would not cost him more than a couple of minutes to type it.Anyway, thank you all for your help and suggestions.
- 0
trombone2k ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thanks for this post-- saved me some time. Here's a version that simply creates an opaque color from a six-digit hex (HTML / CSS) style color code:
#define OPAQUE_HEXCOLOR(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0
green:((c>>8)&0xFF)/255.0
blue:(c&0xFF)/255.0
alpha:1.0]; - 0
the doug ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I don't know anything about the criticism of Scott - but thanks for the little color function.
- 0
LucasTizma199 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
It's really annoying when people throw "RTFM" responses immediately. I perceive these comments as "How dare you waste my time with your amateurish question?" Of course, there are cases where people constantly ask questions with obvious answers, but if you're going to go through the trouble of posting a response ANYWAY, don't bother inserting the elitist "RTFM" response. Either don't respond, or give a direct answer.