IOS天气预报(美化)
【摘要】
接口调试 http://www.zdoz.net/interfaces.aspx#weat-link
气象天气来自中国天气网
http://www.weather.com.cn
工程地址:http://download.csdn.net/download/zzzili/5043081
天气预报城市代码
...
接口调试 http://www.zdoz.net/interfaces.aspx#weat-link

气象天气来自中国天气网
工程地址:http://download.csdn.net/download/zzzili/5043081
天气预报城市代码
http://blog.csdn.net/zzzili/article/details/9045205
图标资源
http://download.csdn.net/detail/zzzili/5536725

效果如图
:
-
-(void)GetWeatherByCityId:(NSString*)cityId
-
{
-
NSURL *URL =[NSURL URLWithString:[NSString stringWithFormat:@"http://www.weather.com.cn/data/cityinfo/%@.html",cityId]];
-
NSError *error;
-
NSString *stringFromFileAtURL = [[NSString alloc]
-
initWithContentsOfURL:URL
-
encoding:NSUTF8StringEncoding
-
error:&error];
-
NSString *strTempL;
-
NSString *strTempH;
-
NSString *strWeather;
-
if(stringFromFileAtURL !=nil)
-
{
-
-
NSLog(stringFromFileAtURL);
-
NSArray *strarray = [stringFromFileAtURL componentsSeparatedByString:@"\""];
-
-
for(int i=0;i<strarray.count;i++)
-
{
-
NSLog([strarray objectAtIndex:i]);
-
NSString *str = [strarray objectAtIndex:i];
-
if(YES == [str isEqualToString:@"temp1"])//最高温度
-
{
-
strTempH = [strarray objectAtIndex:i+2];
-
}
-
else if(YES == [str isEqualToString:@"temp2"])//最低温度
-
{
-
strTempL = [strarray objectAtIndex:i+2];
-
}
-
else if(YES == [str isEqualToString:@"weather"])//天气
-
{
-
strWeather = [strarray objectAtIndex:i+2];
-
}
-
-
}
-
-
-
NSString *sweather = [[NSString alloc]initWithFormat:@"%@\n%@~%@",strWeather,strTempL,strTempH];
-
if(sweather !=nil)
-
self.labelWeather.text = sweather;
-
-
-
NSRange range = [strWeather rangeOfString:@"转"];
-
if(range.location != NSNotFound)
-
{
-
range.location += 1;
-
range.length = strWeather.length - range.location;
-
strWeather = [strWeather substringWithRange:range];
-
}
-
range = [strWeather rangeOfString:@"到"];
-
if(range.location != NSNotFound)
-
{
-
range.location += 1;
-
range.length = strWeather.length - range.location;
-
strWeather = [strWeather substringWithRange:range];
-
}
-
//获取当前时间
-
NSDate *date = [NSDate date];
-
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
-
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
-
comps = [calendar components:NSHourCalendarUnit fromDate:date];
-
int hour = comps.hour;
-
-
NSString *fileName;
-
if(hour>6&&hour<18)
-
{
-
fileName = [[NSString alloc ]initWithFormat:@"%@日.png",strWeather];
-
}
-
else
-
{
-
fileName = [[NSString alloc ]initWithFormat:@"%@夜.png",strWeather];
-
}
-
NSLog(fileName);
-
self.imgWeather.image = [UIImage imageNamed:fileName];
-
[fileName release];
-
}
-
}
文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。
原文链接:zzzili.blog.csdn.net/article/details/8558795
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:cloudbbs@huaweicloud.com进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
- 点赞
- 收藏
- 关注作者

评论(0)