如何在iOS应用程序中使用svg图像 [英] How can I use svg images within my iOS application

查看:335
本文介绍了如何在iOS应用程序中使用svg图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除我用于ios应用程序的.png文件,并添加.svg文件而不是那些。我怎么能在Xcode中做这个。我想用svg图像作为背景和所有图标,按钮。

I want to remove the .png files that I used for my ios app and add .svg files instead of those. How can I do in this in Xcode.I want to use svg images for backgrounds and all icons,buttons.

谢谢

推荐答案

是!!!

IOS safari从版本3.1开始支持svg http://caniuse.com/svg

IOS safari has svg support since version 3.1 http://caniuse.com/svg

它也是我的理解是ios支持将svg用于图像标签 http://phrogz.net/SVG/ svg-via-img.html

It is also my understanding that ios supports using svg with an image tag http://phrogz.net/SVG/svg-via-img.html

IE

<img src="myimage.svg"/>

一般来说,为了与早期的浏览器兼容,内联svg应该在像这样的xhtml文档中提供。

Generally speaking for compatibility with earlier browsers inline svg should be delivered in an xhtml document like this one.

 <!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"><head> 
  <title>Create SVG Elements HTML</title>
  <style type="text/css" media="screen">
    body { background:#eee; margin:0 }
    svg {
      display:block; border:1px solid #ccc; position:absolute;
      top:5%; left:5%; width:90%; height:90%; background:#fff;
    }
    .face { stroke:#000; stroke-width:20px; stroke-linecap:round }
  </style>
</head><body>
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="-350 -250 700 500">
    <circle r="200" class="face" fill="red" />
  </svg>
  <script type="text/javascript"><![CDATA[
    var svg  = document.getElementsByTagName('svg')[0];
    var svgNS = svg.getAttribute('xmlns');

    function createOn( root, name, attrs ){
      var el = document.createElementNS(svgNS,name);
      for (var attr in attrs){
        if (attrs.hasOwnProperty(attr)) el.setAttribute(attr,attrs[attr]);
      }
      return root.appendChild(el);
    }

    createOn( svg, 'path', {
      fill:"none", "class":"face", transform:"translate(-396,-230)",
      d:"M487.41,282.411c-15.07,36.137-50.735,61.537-92.333,61.537 \
        c-41.421,0-76.961-25.185-92.142-61.076"
    });
    createOn( svg, 'circle', { cx:-60, cy:-50, r:20, fill:'#000' });
    createOn( svg, 'circle', { cx: 60, cy:-50, r:20, fill:'#000' });
  ]]></script>
</body></html>

SVG文件应该以mimi类型的image / svg + xml提供,通常在服务器已经,但svg可以与PHP包装一起提供,以具有正确的mimi类型,如果服务器不是最新的mimi类型..

SVG files should be delivered with a mimi type of "image/svg+xml" generally configured on the server already but svg can be delivered with a php wrapper to have the correct mimi type, if the server is not upto date on mimi types..

<?php
   header("Content-Type: image/svg+xml"); /* my host is to cheap to already support svg */
   include("mysvg.svg");
?>

这篇关于如何在iOS应用程序中使用svg图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆