UIColor result in NSString problem?
NSString *st = [[UIColor greenColor] description]; it gives wrong output. i want to get the Result , st must be @"greenColor" as a NSStrin开发者_StackOverflow社区g any help please?
greenColor
is just the name of a class method on UIColor
. Once the UIColor
is constructed it doesn't know it's a greenColor
- it just knows that it has colour values that happen to make green.
So I'd suggest one of two things.
- Create a category on
UIColor
that interceptsdescription
and compares the colour values against the set of colour constructors and return the appropriate string. - Subclass
UIColor
and store a colour name string. Supply adescription
method that just returns that string.
I suspect (2) is simpler but requires that you are able to use your subclassed version instead of UIColor
.
精彩评论