我正在开发一个 RSS 阅读器,我需要为每个提要获取 favicon。例如,如果我的提要是 google.com,我想获取“G”图标并将其放入 UIImage 或其他内容中。关于如何实现这一目标的任何想法?
问问题
4296 次
3 回答
19
最简单的方法是使用谷歌:
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];
那应该行得通。
您只需替换要查询图标的域。
于 2012-02-02T23:37:23.070 回答
3
如果您想要 favicon,请尝试http://www.google.com/s2/favicons?domain=<rss_domain>
在您的应用程序中调用此 URL:
[NSURLConnection connectionWithRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://www.google.com/s2/favicons?domain=google.com"]]
delegate:self];
否则,RSS 频道的元数据有一个可选元素 ,<image>
如下所述:http ://www.rssboard.org/rss-specification#ltimagegtSubelementOfLtchannelgt
例如:
<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>
...
此图像通常比网站的图标更大,并且可能不是方形的,但通过一些巧妙的裁剪和缩放,如果提要的图标不可用,它可以用作图标。
于 2012-02-02T23:50:43.863 回答
-7
如果将图像保存到桌面,
1) 将图像拖入 xcode 2) 转到界面构建器 3) 选择 UIImage 后转到身份检查器 4) 在image
下拉框下,选择图像的名称。
希望有帮助!
于 2012-02-03T02:03:20.450 回答