How to form CGPoint array in Objective C

后端 未结 5 1225
我寻月下人不归
我寻月下人不归 2021-01-31 09:07

I want to get this structure

CGPoint addLines1[] =
{
    CGPointMake(30.0, 150.0),
    CGPointMake(41.67, 145.19),
    CGPointMake(53.33, 103.25),
    CGPointMak         


        
5条回答
  •  一个人的身影
    2021-01-31 09:43

    I tried Tibidabo's answer, and it didn't work for me. It said [myCGPointArray objectAtIndex:0] was of type id, so I couldn't call CGPointValue on it. hm.

    this worked however:

    NSArray *points = [NSArray arrayWithObjects:
                       [NSValue valueWithCGPoint:CGPointMake(5.5, 6.6)],
                       [NSValue valueWithCGPoint:CGPointMake(7.7, 8.8)],
                       nil];
    
    NSValue *val = [points objectAtIndex:0];
    CGPoint point = [val CGPointValue];
    float X = point.x;
    NSLog(@"cgpoint value is: %f", X);
    

    or

    NSArray *points = [NSArray arrayWithObjects:
                            [NSValue valueWithCGPoint:CGPointMake(20, 6.6)],
                            [NSValue valueWithCGPoint:CGPointMake(7.7, 8.8)],
                            nil];
    float xCoordinate = [[points objectAtIndex:0] CGPointValue].x;
    

    I found it here: How can I add CGPoint objects to an NSArray the easy way?, posted by Jarret Hardie.

提交回复
热议问题