У меня есть около 20 простых фигур, нарисованных внутри слоев CAL, как показано ниже (CGPaths нарисованы в слое CAShapelayer). Прямо сейчас у меня есть действительно длинный файл со всеми 20 фигурами в этом формате. Когда родительский UIView создается, он загружает одну из этих фигур на основе того, что было выбрано на предыдущем экране. Это работает нормально, но поддерживать код формы слишком громоздко. Как лучше всего взять приведенный ниже блок кода и сохранить его в отдельном файле, который я мог бы вызывать и выполнять при необходимости (например, star.txt, apple.txt, moon.txt, tree.txt):
CALayer* root = [[CALayer alloc] init];
root.name = nil;
root.bounds = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
root.frame = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
[root addSublayer:root];
[root release];
CALayer* root_layer1 = [[CALayer alloc] init];
root_layer1.name = nil;
root_layer1.bounds = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
root_layer1.frame = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
[someUIView.layer addSublayer:root_layer1];
[root_layer1 release];
CAShapeLayer* root_layer1_layer2 = [[CAShapeLayer alloc] init];
CGMutablePathRef root_layer1_layer2_path_pathref = CGPathCreateMutable();
CGPathMoveToPoint(root_layer1_layer2_path_pathref, NULL, 415.493011, 49.774002);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 448.989014, 153.523010);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 458.575012, 183.251007, 485.170044, 202.583008, 516.384033, 202.510010);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 625.388062, 202.293015);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 656.602051, 202.221008, 683.138062, 221.466003, 692.754028, 251.121002);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 702.427002, 280.804993, 692.263000, 311.960999, 666.968018, 330.239014);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 578.668030, 394.154022);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 553.344055, 412.461029, 543.209045, 443.704010, 552.911011, 473.402039);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 586.781006, 577.006042);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 596.483032, 606.632019, 586.377014, 637.818054, 561.169006, 656.152039);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 535.932983, 674.488037, 503.158997, 674.460022, 477.981018, 656.066040);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 389.881012, 591.846069);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 364.645020, 573.423096, 331.842010, 573.423096, 306.546997, 591.846069);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 218.506989, 656.066040);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 193.298981, 674.460022, 160.525986, 674.488037, 135.287994, 656.152039);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 110.079987, 637.817017, 99.973999, 606.631042, 109.675995, 577.006042);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 143.546997, 473.402039);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 153.276993, 443.704041, 143.112991, 412.461029, 117.789993, 394.154053);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 29.460999, 330.239990);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 4.194000, 311.961975, -5.970001, 280.804993, 3.674999, 251.122009);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 13.320000, 221.467010, 39.856003, 202.222015, 71.041000, 202.294006);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 180.074005, 202.511002);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 211.288010, 202.583008, 237.882019, 183.251007, 247.497009, 153.524002);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 280.964020, 49.775002);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 290.523010, 20.106003, 317.029022, 0.789001, 348.243011, 0.789001);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 379.398987, 0.787998, 405.936005, 20.105000, 415.493011, 49.774002);
root_layer1_layer2.path = root_layer1_layer2_path_pathref;
CGColorSpaceRef root_layer1_layer2_fillColor_colorref_colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat root_layer1_layer2_fillColor_colorref_colorComponents[] = {0.858824,0.529412,0.725490,1.000000};
CGColorRef root_layer1_layer2_fillColor_colorref = CGColorCreate(root_layer1_layer2_fillColor_colorref_colorSpace, root_layer1_layer2_fillColor_colorref_colorComponents);
root_layer1_layer2.fillColor = root_layer1_layer2_fillColor_colorref;
root_layer1_layer2.fillRule = @"non-zero";
root_layer1_layer2.strokeColor = 0;
root_layer1_layer2.lineWidth = 1.000000;
root_layer1_layer2.miterLimit = 10.000000;
root_layer1_layer2.lineCap = @"butt";
root_layer1_layer2.lineJoin = @"miter";
root_layer1_layer2.lineDashPhase = 0.000000;
root_layer1_layer2.lineDashPattern = nil;
root_layer1_layer2.name = nil;
root_layer1_layer2.bounds = CGRectMake(0.000000, 0.000000, 697.000000, 670.000000);
root_layer1_layer2.frame = CGRectMake(36.000000, 40.000000, 697.000000, 670.000000);
[root_layer1 addSublayer:root_layer1_layer2];
[root_layer1_layer2 release];