Andrew
Andrew

Reputation: 16051

How do i use the return function, when it requires passing data?

I'm using this code:

http://imthi.com/blog/programming/iphone-sdk-convert-hex-color-string-to-uicolor.php

But i'm unsure as to how to get it to run that code on my NSString from somewhere else.

How do i use return here?

Upvotes: 0

Views: 70

Answers (2)

Jordan
Jordan

Reputation: 21770

Create two files

NSString+meltutils.h and NSString+meltutils.m

Put the content from the post into the respective files. Then in your program add this to the top of the file:

"#import “NSString+meltutils.h” // no quotes

Then somewhere in your program do this:

UIColor *aColorStr = [@"yourStringHere" toUIColor];

Upvotes: 1

drudru
drudru

Reputation: 5023

Look in the comments on that post.

He creates a category for NSString. This essentially adds methods to NSString (kinda like monkey patching in Ruby).

Once you do that, you can take an NSString that has a hexcolor string value and call toUIColor and receive a UIColor object.

Upvotes: 0

Related Questions