从SVGstring创build一个UIImage

嗨,我试图从我从服务器获得的数据呈现SVG图像。

我用一个名为SVGgh的库使用这个代码 –

NSData *svgData = [[NSData alloc] initWithBase64EncodedString:svgStr options:0]; NSString* newStr = [[NSString alloc] initWithData:svgData encoding:NSUTF8StringEncoding]; NSString *finalString = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">%@", newStr]; aRenderer = [[SVGRenderer alloc] initWithString:finalString]; UIImage *image = [aRenderer asImageWithSize:CGSizeMake(200, 200) andScale:1.0]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = CGRectMake(0, 0, 200.0, 200.0); imageView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:imageView]; 

但我得到的只是一个黑色的视angular。 有人能指导我发生什么事吗?

这里是我传递的string – 这是后面的数据:

  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 259.6 312.79"><defs><style>.a,.e{font-size:18px;}.a,.c,.e,.f{font-family:Iowan Old Style;}.a,.c{font-style:italic;}.b,.d{fill:none;}.c{font-size:23px;}.d{stroke:#000;}.f{font-size:16px;}</style></defs><title>ACT-Math-7862-q</title><text class="a" transform="translate(70.83 217.15)">H</text><rect class="b" x="-435.5" y="-153.52" width="1024" height="768"/><text class="c" transform="translate(222.5 266.48)">x</text><rect class="b" x="222.15" y="241.56" width="9.06" height="25"/><polyline class="d" points="1 255.5 209.82 255.5 210.82 255.5"/><polygon points="209.82 260.3 219.42 255.5 209.82 250.7 209.82 260.3"/><rect class="b" y="249.7" width="220.42" height="11.6"/><text class="c" transform="translate(33.5 24.48)">y</text><rect class="b" x="25.85" width="25.74" height="30"/><polyline class="d" points="38.2 286.16 38.2 43.42 38.2 42.42"/><polygon points="43 43.42 38.2 33.82 33.4 43.42 43 43.42"/><rect class="b" x="-435.5" y="-153.52" width="1024" height="768"/><rect class="b" x="32.4" y="32.82" width="11.6" height="254.33"/><text class="e" transform="translate(190.5 216.48)">(8,2)</text><text class="e" transform="translate(62.5 106.48)">(1,5)</text><text class="a" transform="translate(52.5 106.48)">J</text><polygon class="d" points="214.68 116.69 181.75 199.81 92.68 199.72 62.12 116.39 214.68 116.69"/><text class="e" transform="translate(86.16 217.15)">(4,2)</text><text class="e" transform="translate(219.5 106.48)">(9,5)</text><text class="a" transform="translate(179.88 217.15)">L</text><text class="a" transform="translate(206.5 106.48)">K</text><rect class="b" x="-435.5" y="-153.52" width="1024" height="768"/><circle cx="214.68" cy="116.69" r="1.87"/><circle cx="62.12" cy="116.4" r="1.87"/><circle cx="92.68" cy="199.72" r="1.87"/><circle cx="181.75" cy="199.82" r="1.87"/><text class="f" transform="translate(22.5 305.48)">Note: <tspan x="44.2" y="0">F</tspan><tspan x="53.27" y="0">igure not drawn to scale.</tspan></text></svg> 

谢谢Shani