作为一名学生, 作为一名iOS开发学习者, 我个人浏览信息包括博客, 更多的选择移动终端。然而, csdn并没有现成的客户端(不过有个web版的)。
之前曾经看到一款开源的导出工具, 但是它是基于Windows平台的。导出的也仅仅是PDF格式。而且, 对于文章的导出, 需要精确URL。无法做到边浏览别导出。
另外, 我想实现的是, 可以在没有网络的情况下, 浏览自己收藏的文章。并且, 对于自己收藏的文章, 可以分类管理。
最关键的是, 对于自己的文章, 可以做一个备份。我曾经遇到过这样一件事, csdn账号密码泄漏, 使得他人登录我账号发表垃圾博文, 导致我的博客被封一天。那时候, 我的博客记录了170篇自己的学习点滴, 没有备份, 可以想像那时候我有多慌。可见, 备份自己文章的重要性。
基于以上种种原因, 这款基于iOS平台的博客导出工具应运而生。
本文章正在参与2014年csdn博客大赛。如果您觉得, 对您有所帮助, 希望能投上宝贵的一票。在最下方投票
· 支持在线浏览csdn博客
· 可导类型包括: 单篇文章, 专栏, 指定作者全部文章
· 导出方式包括: (1)导出单前浏览博文/专家/专栏 (2)导出指定URL博文/专家/专栏
· 导出文章分类管理
· 导出文章查询功能
· 导出文章自动排版, 图片自适应, 可放缩
看到这里, 如果你只是想体验一下这个应用, 想看看源码, 那可以从我的Github中下载。另外, 第一版已经上传到App Store上去了。 正在等待审核。
http://code.google.com/p/http://www.https://github.com/colin1994/csdnBlog.git
如果你想了解下整体开发过程, 欢迎继续往下看。推荐下载了源码, 对照着看。
· 自定义启动动画
· 网络环境判断(是否是Wi-Fi状态)
· IOS与JavaScript的交互
· 自定义HUD加载效果(非传统菊花)
· UITableView列表基本操作
· 列表关键字模糊查询
· 图片基本操作
下面逐一进行分析。
不同与传统的修改LaunchImage来加载一个静态的图片作为我们的欢迎界面, 我这里简单的实现了图片缩放, 文字渐渐显示的效果。
相对来说, 更加美观, 我们能做的操作也更加多。
打开AppDelegate.h文件, 声明一个变量, 用于显示我们的视图。
[cpp] view plaincopy
1 @property (strong, nonatomic) UIImageView *splashView;
打开AppDelegate.m文件, 加入具体实现过程。
[cpp] view plaincopy
2 //添加启动动画
3 [self.window makeKeyAndVisible];
4
5 splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, Screen_height)];
6
7 if ([[UIScreen mainScreen] bounds].size.height == 568)
8 {
9 [splashView setImage:[UIImage imageNamed:@"bgBlog-568"]];
10 }
11 else
12 {
13 [splashView setImage:[UIImage imageNamed:@"bgBlog"]];
14
15 }
16
17 [self.window addSubview:splashView];
18 [self.window bringSubviewToFront:splashView];
19
20 [self performSelector:@selector(scale) withObject:nil afterDelay:0.0f];
21 [self performSelector:@selector(showWord) withObject:nil afterDelay:2.5f];
[cpp] view plaincopy
22 -(void)scale
23 {
24 UIImageView *logo_ = [[UIImageView alloc]initWithFrame:CGRectMake(119, 88, 82, 82)];
25 logo_.image = [UIImage imageNamed:@"csdnLogo"];
26 [splashView addSubview:logo_];
27 [self setAnimation:logo_];
28 }
29
30 -(void)setAnimation:(UIImageView *)nowView
31 {
32
33 [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear
34 animations:^
35 {
36 // 执行的动画code
37 [nowView setFrame:CGRectMake(nowView.frame.origin.x- nowView.frame.size.width*0.1, nowView.frame.origin.y-nowView.frame.size.height*0.1, nowView.frame.size.width*1.2, nowView.frame.size.height*1.2)];
38 }
39 completion:^(BOOL finished)
40 {
41 // 完成后执行code
42 [nowView removeFromSuperview];
43 }
44 ];
45
46 }
47
48 -(void)showWord
49 {
50
51 UIImageView *word_ = [[UIImageView alloc]initWithFrame:CGRectMake(75, Screen_height-100, 170, 29)];
52 word_.image = [UIImage imageNamed:@"word_"];
53 [splashView addSubview:word_];
54
55 word_.alpha = 0.0;
56 [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear
57 animations:^
58 {
59 word_.alpha = 1.0;
60 }
61 completion:^(BOOL finished)
62 {
63 // 完成后执行code
64 [NSThread sleepForTimeInterval:1.0f];
65 [splashView removeFromSuperview];
66 }
67 ];
68 }
这个需要导入Wi-Fi文件夹下的Reachability.h / .m文件。 这是从苹果官方下载的。一个用来判断网络环境的文件。
我们之所以要判断是否在Wi-Fi环境下, 是因为导出文章可能使用的流量较大, 我们需要提示用户开启Wi-Fi来下载。
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262062
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262198
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262226
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262281
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262308
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262323
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262346
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262356
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262371
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262386
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119517
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262429
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262442
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262458
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262469
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4262478
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/670129/rz/2639209.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2639083.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638828.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638535.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638571.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638601.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638623.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638637.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638658.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638672.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/313476/rz/2638696.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/670129/rz/2639285.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/670129/rz/2639334.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/670129/rz/2639357.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/670129/rz/2639818.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/670129/rz/2639831.shtml
http://code.google.com/p/http://www.http://eqzone.51etong.com/u/670129/rz/2639860.shtml
http://code.google.com/p/http://www.http://www.nalichi.com/diary/home/show/197354.html
http://code.google.com/p/http://www.http://www.nalichi.com/diary/home/show/197374.html
http://code.google.com/p/http://www.http://www.nalichi.com/diary/home/show/197126.html
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119522
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119521
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119520
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119519
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119518
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119523
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119525
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119526
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119528
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=321&tid=119529
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66m0-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66gg-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66hh-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66qj-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66sj-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66ah-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66zw-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66ua-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o66ng-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6kyy-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k5_-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k_r-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k60-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k6x-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6kk4-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k3f-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k03-evqok
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264531
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264557
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264566
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264577
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264589
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264599
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264612
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264628
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264637
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264656
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264705
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264723
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264742
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264749
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264756
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264768
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264774
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264783
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264789
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264802
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119596
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119597
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119598
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119600
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119603
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119606
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96350.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96352.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96354.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96361.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96362.htm
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4264997
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265016
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265041
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265057
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265071
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265087
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265107
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265133
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265142
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6kbv-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6kj2-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6krh-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6kwt-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k8l-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6kmu-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6k2u-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o6kxd-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o630f-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o631k-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o639b-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o63rl-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o63u1-evqok
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o632r-evqok
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96395.htm
http://code.google.com/p/http://www.http://me2day.net/pyxcc03/2014/06/21/p5o60ya-evqok
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266398
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266428
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266449
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266440
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119614
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119611
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119610
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119609
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96370.htm
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265158
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265170
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265187
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265213
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265233
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265370
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265386
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265404
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265418
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265477
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265504
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265518
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266049
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266058
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266081
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266100
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266127
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266139
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266153
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266190
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266207
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266218
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266274
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266329
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266423
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119639
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119637
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119635
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119633
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119632
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119631
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119630
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119629
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=209&tid=119626
http://code.google.com/p/http://www.http://www.kaoder.com/?m=thread&a=view&fid=219&tid=119622
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96376.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96379.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96396.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96401.htm
http://code.google.com/p/http://www.http://www.3688.tv/bbs/detail/96403.htm
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4266001
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265978
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265949
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265868
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265825
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265812
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265792
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265780
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265759
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265735
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265715
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265685
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265661
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265623
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265598
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265569
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265556
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265537
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265345
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265317
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265296
http://code.google.com/p/http://www.http://www.beihai365.com/read.php?tid=4265256
http://code.google.com/p/http://www.http://www.aibang.com/catalog/151841967-421346084/product/128953.html
http://code.google.com/p/http://www.http://www.aibang.com/catalog/151841967-421346084/product/128933.html
http://code.google.com/p/http://www.http://www.aibang.com/catalog/151841967-421346084/product/128943.html
2.
[cpp] view plaincopy
69 #import "Reachability.h" //Wi-Fi
[cpp] view plaincopy
70 if ([Reachability reachabilityForInternetConnection].currentReachabilityStatus == ReachableViaWiFi)
71 {
72 //添加你想做的事情
73 }
UIWebView是iOS最常用的SDK之一,它有一个stringByEvaluatingJavaScriptFromString方法可以将javascript嵌入页面中,通过这个方法我们可以在iOS中与UIWebView中的网页元素交互。
常见的几种使用途径:
1、获取当前页面的url。
[cpp] view plaincopy
74 - (void)webViewDidFinishLoad:(UIWebView *)webView {
75 NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
76 }
2、获取页面title。
[cpp] view plaincopy
77 - (void)webViewDidFinishLoad:(UIWebView *)webView {
78 NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
79
80 NSString *title = [webview stringByEvaluatingJavaScriptFromString:@"document.title"];
81 }
3、修改界面元素的值。
[cpp] view plaincopy
82 NSString *js_result = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('q')[0].value='Colin';"];
4、表单提交:
[cpp] view plaincopy
83 NSString *js_result2 = [webView stringByEvaluatingJavaScriptFromString:@"document.forms[0].submit(); "];
当然, 还有更多的功能, 需要你自己去学习。
我们这个工具所要做的是, 获取到博文的主要内容及其标题。
以导出单篇为例。
我们打开一个博文, 显示页面源代码, 可以看到下面这样的内容。
其中的"article_content" 就对应着csdn博文的正文内容. 这是我们导出过程中需要的。(你肯定也不希望导出的文章里面嵌套着广告吧...)
所以, 我们可以通过简单的两行代码获取我们需要的内容:
[cpp] view plaincopy
84 //获取详细内容
85 NSString *lJs = @"document.getElementById(\"article_content\").innerHTML";
86 NSString *lHtml1 = [webView stringByEvaluatingJavaScriptFromString:lJs];
同理, 文章标题可以这样获得:
[cpp] view plaincopy
87 //获取标题
88 NSString *lJs2 = @"document.getElementById(\"article_details\").getElementsByClassName(\"article_title\")[0].getElementsByTagName(\"a\")[0].innerText";
89 NSString *lHtml2 = [webView stringByEvaluatingJavaScriptFromString:lJs2];
再深入一点, 我们甚至可以修改显示网页的图片大小
[cpp] view plaincopy
90 //修改图片大小
91 if ([lHtml1 rangeOfString:@"<img"].location != NSNotFound)
92 {
93 NSScanner *myScanner = [NSScanner scannerWithString:lHtml1];
94 NSString *myText = nil;
95 while ([myScanner isAtEnd] == NO)
96 {
97 [myScanner scanUpToString:@"<img" intoString:nil];
98 [myScanner scanUpToString:@"s" intoString:&myText];
99
100 lHtml1 = [lHtml1 stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@s",myText] withString:@"<img style=\"width:300px;height:this.offsetHeight;\" s"];
101 }
102 }
iOS自带的加载效果是个转圈的菊花...想必大家都清楚了。
不过说实话, 那玩意确实够难看的。
选择我们要做的是, 显示一个不封闭的圈, 并且背景视图暗一点, 突出加载过程。
效果如下:
[cpp] view plaincopy
103 #import "SVProgressHUD.h" //HUD 加载显示
[cpp] view plaincopy
104 //显示HUD
105 [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeGradient];
[cpp] view plaincopy
106 //移除HUD
107 [SVProgressHUD dismiss];
这个是基础内容了, 具体可以看blogExportedList.m这里. 有详细讲解。
这里着重介绍下左滑删除操作。
1.开启运行删除模式
2.响应删除的时候, 需要做到 (1) 从列表中移除 (2)从数据中移除 (3)刷新列表
[cpp] view plaincopy
108 //删除
109 -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
110 {
111 return UITableViewCellEditingStyleDelete;
112 }
113
114 /*改变删除按钮的title*/
115 -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
116 {
117 return @"删除";
118 }
119
120 /*删除用到的函数*/
121 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
122 {
123 if (editingStyle == UITableViewCellEditingStyleDelete)
124 {
125 //获取完整路径 以及字典和数组的初始化
126 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
127 NSString *documentsDirectory = [paths objectAtIndex:0];
128 NSString * namePath = [documentsDirectory stringByAppendingPathComponent:@"csdnInfo.plist"];
129
130 [blogArr removeObjectAtIndex:indexPath.row];
131
132 [blogArr writeToFile:namePath atomically:YES];
133
134 [nameList removeObjectAtIndex:indexPath.row];
135
136 [myTableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; //删除对应数据的cell
137 }
138 }