使用NSFttributedString通过swift 3加载HTML数据时设置字体失败?

时间:2018-02-23 08:04:55

标签: ios swift nsattributedstring

此代码完美无缺 但我有一个问题,我想加载HTML数据并更改它的字体 我尝试使用NSAttributedString来设置UIFont,它对我不起作用。
我该怎么做才能更改HTML数据字体,并计算它的高度正确?
谢谢。

 private Bitmap fetchFavicon(Uri uri) {
        final Uri iconUri = uri.buildUpon().path("favicon.ico").build();
        Log.i(TAG, "Fetching favicon from: " + iconUri);

        InputStream is = null;
        BufferedInputStream bis = null;
        try
        {
            URLConnection conn = new URL(iconUri.toString()).openConnection();
            conn.connect();
            is = conn.getInputStream();
            bis = new BufferedInputStream(is, 8192);
            return BitmapFactory.decodeStream(bis);
        } catch (IOException e) {
            Log.w(TAG, "Failed to fetch favicon from " + iconUri, e);
            return null;
        }
    }

1 个答案:

答案 0 :(得分:1)

 ->   You can try this

let myDescriptionHTML = "<html><head> <style type=\"text/css\"> body{color:red;}<style>img{display:inline;height:auto;max-width:100%;}body {font-family:\"Eurostile LT\";font-size:20;} p {margin:0px!important; color:black !important;}</style></head><body>\(Your Word)</body></html>" as String

 print(myDescriptionHTML)