Reputation: 120334
How can I obtain a CGAffineTransform
from a NSString
in Cocoa?
On iOS there is CGAffineTransformFromString
.
Upvotes: 1
Views: 491
Reputation: 120334
For lack of a better solution I'm currently doing this:
CGAffineTransform CGAffineTransformFromString(NSString *string)
{
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"[ ]"]];
NSArray *components = [string componentsSeparatedByString:@","];
CGAffineTransform transform;
transform.a = [[components objectAtIndex:0] floatValue];
transform.b = [[components objectAtIndex:1] floatValue];
transform.c = [[components objectAtIndex:2] floatValue];
transform.d = [[components objectAtIndex:3] floatValue];
transform.tx = [[components objectAtIndex:4] floatValue];
transform.ty = [[components objectAtIndex:5] floatValue];
return transform;
}
Upvotes: 2