简体   繁体   English

UIImage:如何获取网站选项卡图标

[英]UIImage: How to get website tab icon

I'm developing an RSS Reader and I need to get the favicon for each feed. 我正在开发RSS阅读器,并且需要为每个供稿获取图标。 For example, if my feed is google.com, I'd like to get the "G" icon and put it into a UIImage or something. 例如,如果我的供稿是google.com,我想获取“ G”图标并将其放入UIImage或其他内容。 Any ideas on how to achieve this? 关于如何实现这一目标的任何想法?

The easiest way to go would be to use Google: 最简单的方法是使用Google:

NSString *myURLString = @"http://www.google.com/s2/favicons?domain=www.stackoverflow.com";
NSURL *myURL=[NSURL URLWithString: myURLString];
NSData *myData=[NSData dataWithContentsOfURL:myURL];

UIImage *myImage=[[UIImage alloc] initWithData:myData];

That should work. 那应该工作。

You would just have to replace the domain where you want to query your icon. 您只需要替换您要查询图标的域即可。

If you want the favicon, try calling this URL: http://www.google.com/s2/favicons?domain=<rss_domain> from within your app: 如果您想要该图标,请尝试在您的应用程序中调用以下URL: http://www.google.com/s2/favicons?domain=<rss_domain> : http://www.google.com/s2/favicons?domain=<rss_domain>

[NSURLConnection connectionWithRequest:
    [NSURLRequest requestWithURL:
        [NSURL URLWithString:@"http://www.google.com/s2/favicons?domain=google.com"]]
                              delegate:self];

Otherwise, an RSS channel's metadata has an optional element, <image> , which is described here: http://www.rssboard.org/rss-specification#ltimagegtSubelementOfLtchannelgt 否则,RSS频道的元数据具有可选元素<image> ,在此处进行描述: http : //www.rssboard.org/rss-specification#ltimagegtSubelementOfLtchannelgt

For example: 例如:

<channel>
    <language>en-us</language>
        <title>Scientific American - News</title>
            <image>
                <title>Scientific American</title>
                <link>http://www.scientificamerican.com</link>
                <width>144</width>
                <url>
                    http://www.scientificamerican.com/media/logo/SAlogo_144px.gif
                </url>
                <height>45</height>
            </image>
        ...

This image will typically be larger than a site's favicon, and likely not-square, but with some clever cropping and scaling, it can work as an icon if a feed's favicon isn't available. 该图像通常会比站点的图标图标大,并且可能不是正方形,但是如果进行了一些巧妙的裁剪和缩放,则在无法使用Feed图标时,它可以用作图标。

If you save the image to your desktop, 如果您将图片保存到桌面,

1) drag image into xcode 2)Go to interface builder 3)Go to the identity inspector after selecting the UIImage 4)Under the image drop down box, select the name of your image. 1)将图像拖到xcode中2)转到界面生成器3)选择UIImage后转到身份检查器4)在image下拉框下,选择图像名称。

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM