开发者

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.

  1. Create a category on UIColor that intercepts description and compares the colour values against the set of colour constructors and return the appropriate string.
  2. Subclass UIColor and store a colour name string. Supply a description 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜