Reachability 檢測網(wǎng)絡(luò)連接
ASIHTTPRequest 網(wǎng)絡(luò)請求
MBProgressHUD 提示效果
SVProgressHUD 提示效果
ZAActivityBar 提示效果
SBJson JSON解析
JSONKit JSON解析
SDWebImage 圖片異步加載及緩存
UIActivityIndicator-for-SDWebImage 為SDWebImage顯示加載效果
UIImage+Resize 調(diào)整圖片大小
ImageCacheResize 異步加載圖片、緩存及調(diào)整大小
EGOTableViewPullRefresh 下拉刷新
PullToRefresh 下拉刷新
STableViewController 下拉刷新、上拉加載更多
SVPullToRefresh 下拉刷新、上拉加載更多
CMPopTipView 提示信息
PrettyKit
MGBox2
Nimbus
FlatUIKit
MUKMediaGallery
PTShowcaseViewController
MWPhotoBrowser
ios-image-filters
PDF Reader Core for iOS
DTCoreText
FTCoreText
CoreTextWrapper
Base64
RNCryptor
在iOS開發(fā)中不可避免的會用到一些第三方類庫,它們提供了很多實用的功能,使我們的開發(fā)變得更有效率;同時,也可以從它們的源代碼中學(xué)習(xí)到很多有用的東西。
Reachability 檢測網(wǎng)絡(luò)連接
用來檢查網(wǎng)絡(luò)連接是否可用:包括WIFI和WWAN(3G/EDGE/CDMA等)兩種工作模式。
可以從Apple網(wǎng)站下載到:http://developer.apple.com/library/ios/#samplecode/Reachability/History/History.html#//apple_ref/doc/uid/DTS40007324-RevisionHistory-DontLinkElementID_1。
現(xiàn)在有更好的替代品:https://github.com/tonymillion/Reachability,比Apple提供的兼容性更好,而且更加好用,更具體的使用方法請看它提供的例子。
1
2
3
4
5
6
7
8
9
|
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
reach.reachableBlock = ^(Reachability*reach) {
NSLog(@"網(wǎng)絡(luò)可用!");
};
reach.unreachableBlock = ^(Reachability*reach) {
NSLog(@"網(wǎng)絡(luò)不可用!");
};
// 開始監(jiān)聽
[reach startNotifier];
|
ASIHTTPRequest 網(wǎng)絡(luò)請求
ASIHTTPRequest是對CFNetwork API的一個包裝,它提供了一套更加簡潔的API,使用起來也更加簡單。
官方網(wǎng)站:http://allseeing-i.com/ASIHTTPRequest/
GitHub:https://github.com/pokeb/asi-http-request
它不僅僅支持基本的HTTP請求,而且支持基于REST的服務(wù)(GET/POST/PUT/DELETE)。
最讓人喜歡的是,它支持block語法:
1
2
[!--empirenews.page--]3
4
5
6
7
8
9
10
11
12
13
|
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
|
它的ASIFormDataRequest子類可以橫容易的提交表單數(shù)據(jù)和文件:
1
2
3
4
5
6
7
8
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
// Upload a file on disk
[request setFile:@"/Users/ben/Desktop/ben.jpg" withFileName:@"myphoto.jpg" andContentType:@"image/jpeg"
forKey:@"photo"];
// Upload an NSData instance
[request setData:imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
|
[!--empirenews.page--]
詳細(xì)的使用方法請下載相應(yīng)的源代碼及例子,或者從官方的使用說明http://allseeing-i.com/ASIHTTPRequest/How-to-use開始。
MBProgressHUD 提示效果
支持各種狀態(tài)加載的提示效果,以及帶進(jìn)度的提示效果。
GitHub:https://github.com/matej/MBProgressHUD
一般會在.m文件實現(xiàn)MBProgressHUDDelegate協(xié)議,并聲明HUD變量:
1
2
3
4
5
6
7
8
9
10
11
12
|
@interface SampleViewController ()<MBProgressHUDDelegate>
{
MBProgressHUD *HUD;
}
#pragma mark -
#pragma mark MBProgressHUDDelegate methods
- (void)hudWasHidden:(MBProgressHUD *)hud {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
HUD = nil;
}
|
在執(zhí)行某個異步請求時開始調(diào)用:
1
2
3
4
5
|
HUD = [MBProgressHUD showHUDAddedTo:self.webView animated:YES];
HUD.labelText = @"正在請求...";
// mode參數(shù)可以控制顯示的模式
//HUD.mode = MBProgressHUDModeText;
HUD.delegate = self;
|
[!--empirenews.page--]
請求完成時隱藏提示效果:
1
|
[HUD hide:YES];
|
對于同步方法一般都是用showWhileExecuting方法,方法執(zhí)行完成之后會自動隱藏提示效果:
1
|
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
|
SVProgressHUD 提示效果
GitHub:https://github.com/samvermette/SVProgressHUD
SVProgressHUD和MBProgressHUD效果差不多,不過不需要使用協(xié)議,同時也不需要聲明實例。
直接通過類方法進(jìn)行調(diào)用即可:
1
|
[SVProgressHUD method]
|
可以使用以下方法來顯示狀態(tài):
1
2
3
4
|
+ (void)show;
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType;
[!--empirenews.page--]+ (void)showWithStatus:(NSString*)string;
+ (void)showWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;
|
如果需要明確的進(jìn)度,則使用以下方法:
1
2
3
|
+ (void)showProgress:(CGFloat)progress;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
|
通過dismiss方法來隱藏提示:
1
|
+ (void)dismiss;
|
另外提供了以下方法用于顯示狀態(tài),并在1秒后自動隱藏提示(使用的圖標(biāo)來源于Glyphish:http://www.glyphish.com/):
1
2
3
|
+ (void)showSuccessWithStatus:(NSString*)string;
+ (void)showErrorWithStatus:(NSString *)string;
+ (void)showImage:(UIImage*)image status:(NSString*)string;// use 28x28 white pngs
|
ZAActivityBar 提示效果
GitHub:https://github.com/zacaltman/ZAActivityBar
ZAActivityBar和SVProgressHUD非常相似,它提供了更加簡潔的API來顯示提示效果。
ZAActivityBar使用的動畫效果來源于ZKBounceAnimation(https://github.com/khanlou/SKBounceAnimation),成功、失敗的狀態(tài)圖標(biāo)來源于Pictos(http://pictos.cc/)。[!--empirenews.page--]
顯示加載狀態(tài):
1
|
[ZAActivityBar showWithStatus:@"加載中..."];
|
顯示成功、失敗狀態(tài):
1
2
|
[ZAActivityBar showSuccessWithStatus:@"成功!"];
[ZAActivityBar showErrorWithStatus:@"失敗!"];
|
隱藏提示:
1
|
[ZAActivityBar dismiss];
|
SBJson JSON解析
官方: http://sbjson.org/
GitHub:https://github.com/stig/json-framework
API使用起來稍顯繁瑣,特別是初始化的時候:
1
2
3
4
5
6
7
8
9
[!--empirenews.page--]10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
@interface TestViewController ()<SBJsonStreamParserAdapterDelegate> {
SBJsonStreamParser *parser;
SBJsonStreamParserAdapter *adapter;
}
// 冗長的初始化方法足以嚇到一大片人
- (void)initSBJSON
{
[!--empirenews.page--] // We don't want *all* the individual messages from the
// SBJsonStreamParser, just the top-level objects. The stream
// parser adapter exists for this purpose.
adapter = [[SBJsonStreamParserAdapter alloc] init];
// Set ourselves as the delegate, so we receive the messages
// from the adapter.
adapter.delegate = self;
// Create a new stream parser..
parser = [[SBJsonStreamParser alloc] init];
// .. and set our adapter as its delegate.
parser.delegate = adapter;
// Normally it's an error if JSON is followed by anything but
// whitespace. Setting this means that the parser will be
// expecting the stream to contain multiple whitespace-separated
// JSON documents.
parser.supportMultipleDocuments = YES;
}
#pragma mark SBJsonStreamParserAdapterDelegate methods
- (void)parser:(SBJsonStreamParser *)parser foundArray:(NSArray *)array {
[NSExceptionraise:@"unexpected" format:@"Should not get here"];
}
- (void)parser:(SBJsonStreamParser *)parser foundObject:(NSDictionary *)dict {
NSLog(@"SBJson parser foundObject");
// 處理返回的數(shù)據(jù)
}
// 使用ASIHTTPRequest請求測試
- (void) loadData {
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request setCompletionBlock:^{
// Use when fetching text data
//NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
NSLog(@"Connection didReceiveData of length: %u", responseData.length);
// Parse the new chunk of data. The parser will append it to
// its internal buffer, then parse from where it left off in
// the last chunk.
SBJsonStreamParserStatus status = [parser parse:responseData];
if (status == SBJsonStreamParserError) {
NSLog(@"Parser error: %@", parser.error);
[!--empirenews.page--] }else if (status == SBJsonStreamParserWaitingForData) {
NSLog(@"Parser waiting for more data");
}
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"failed - %@ %@", [error localizedDescription], error);
}];
[request startAsynchronous];
}
|
JSONKit JSON解析
GitHub:https://github.com/johnezang/JSONKit
提供比SBJson更優(yōu)異的性能以及更加簡便的使用方法,但是中文最好使用utf-8格式(\uXXXX),否則容易造成亂碼。
API調(diào)用起來非常簡單,省去了SBJson那么一大堆的方法:
1
2
|
JSONDecoder* decoder = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionNone];
id result = [decoder objectWithData:jsonData];
|
詳細(xì)的使用方法請看它的GitHub主頁。
SDWebImage 圖片異步加載及緩存
SDWebImage用于異步下載網(wǎng)絡(luò)上的圖片,并支持對圖片的緩存等。
多數(shù)情況下是使用UIImageView+WebCache為UIImageView異步加載圖片:
1
2
3
4
|
#import <SDWebImage/UIImageView+WebCache.h>
// ...
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
|
需要注意的是,pladeholderImage的大小一定要大于UIImageView的大小,否則可能不顯示placeholderImage圖片。
它還支持block語法用于在加載完成時做一些操作:
[!--empirenews.page--]1
2
3
|
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {... completion code here ...}];
|
SDWebImage并不局限于UIImageView上,使用SDWebImageManager完成更多的操作:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
options:0
progress:^(NSUInteger receivedSize,long long expectedSize)
{
// 下載進(jìn)度
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
{
if (image)
{
// 下載完成
}
}];
|
或者使用Image Downloader也是一樣的效果:
[!--empirenews.page--]1
2
3
4
5
6
7
8
9
10
11
12
13
|
[SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
options:0
progress:^(NSUInteger receivedSize,long long expectedSize)
{
// 進(jìn)度
}
completed:^(UIImage *image, NSData *data, NSError *error,BOOL finished)
{
if (image && finished)
{
// 下載完成
}
}];
|
UIActivityIndicator-for-SDWebImage 為SDWebImage顯示加載效果
GitHub:https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage
用于為SDWebImage在UIImageView加載圖片時,顯示加載效果(UIActivityIndicatorView實現(xiàn)),它提供以下方法:
1
2
3
4
5
6
7
|
- (void)setImageWithURL:(NSURL *)url usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
[!--empirenews.page--]- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
|
UIImage+Resize 調(diào)整圖片大小
GitHub:https://github.com/coryalder/UIImage_Resize
提供多種方法為圖片設(shè)置透明度、圓角、裁剪、調(diào)整大小等:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
- (UIImage *)imageWithAlpha;
- (UIImage *)transparentBorderImage:(NSUInteger)borderSize;
- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize;
- (UIImage *)croppedImage:(CGRect)bounds;
- (UIImage *)thumbnailImage:(NSInteger)thumbnailSize
transparentBorder:(NSUInteger)borderSize
cornerRadius:(NSUInteger)cornerRadius
interpolationQuality:(CGInterpolationQuality)quality;
- (UIImage *)resizedImage:(CGSize)newSize
interpolationQuality:(CGInterpolationQuality)quality;
- (UIImage *)
resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality;
|
更詳細(xì)使用見:http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/
ImageCacheResize 異步加載圖片、緩存及調(diào)整大小
GitHub:https://github.com/toptierlabs/ImageCacheResize
整合了SDWebImage和UIImage+Resize的功能,用于圖片的異步加載、緩存、以及下載完成后調(diào)整大小并顯示在UIImageView上。
提供了以下API用于加載圖片以及加載完成后調(diào)整圖片大?。?/p>
[!--empirenews.page--]1
2
3
4
5
6
|
- (void)setImageWithURL:(NSURL *)url andCropToBounds:(CGRect)bounds;
- (void)setImageWithURL:(NSURL *)url andResize:(CGSize)size withContentMode:(UIViewContentMode)mode;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder andCropToBounds:(CGRect)bounds;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options andResize:(CGSize)size;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options andResize:(CGSize)size withContentMode:(UIViewContentMode)mode;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options andCropToBounds:(CGRect)bounds;
|
使用方法和SDWebImage一樣簡單,如以下官方例子:
1
2
|
[imageview setImageWithURL:[NSURL URLWithString:@"http://t0.gstatic.com/images?q=tbn:ANd9GcQfraHpiabjEY8iDdBe9OUQYHMtwfuAv9ZRR0RYKuoVF_EpE8Fp5A"] andResize:CGSizeMake(30, 30) withContentMode:UIViewContentModeScaleAspectFit]; // 按比例縮放
[imageview setImageWithURL:[NSURL URLWithString:@"http://t0.gstatic.com/images?q=tbn:ANd9GcQfraHpiabjEY8iDdBe9OUQYHMtwfuAv9ZRR0RYKuoVF_EpE8Fp5A"] andCropToBounds:CGRectMake(0, 0, 100, 100)]; // 裁剪成100x100大小
|
EGOTableViewPullRefresh 下拉刷新
GitHub:https://github.com/enormego/EGOTableViewPullRefresh
這是最早出現(xiàn)的為UITableView提供下拉刷新功能的類庫,使用起來稍顯麻煩,需要實現(xiàn)諸多協(xié)議(代碼取自官方DEMO):
1
[!--empirenews.page--]2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#import "EGORefreshTableHeaderView.h"
@interface RootViewController : UITableViewController <EGORefreshTableHeaderDelegate, UITableViewDelegate, UITableViewDataSource>{
EGORefreshTableHeaderView *_refreshHeaderView;
// 是否正在加載中
BOOL _reloading;
[!--empirenews.page--]}
- (void)viewDidLoad {
[super viewDidLoad];
if (_refreshHeaderView == nil) {
EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
view.delegate = self;
[self.tableView addSubview:view];
_refreshHeaderView = view;
[view release];
}
// 更新最后加載時間
[_refreshHeaderView refreshLastUpdatedDate];
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods
- (void)reloadTableViewDataSource{
// 在這里加入代碼用于獲取數(shù)據(jù)
_reloading = YES;
}
- (void)doneLoadingTableViewData{
// 數(shù)據(jù)加載完成時調(diào)用這個方法
_reloading = NO;
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
}
#pragma mark -
#pragma mark UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}
#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods
- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
[self reloadTableViewDataSource];
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
}
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
return _reloading;// should return if data source model is reloading
}
- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
return [NSDate date];// should return date data source was last changed
}
|
[!--empirenews.page--]
PullToRefresh 下拉刷新
GitHub:https://github.com/leah/PullToRefresh
PullToRefresh提供比EGOTableViewPullRefresh更加簡單的使用方法,只要繼承自PullRefreshTableViewController,再實現(xiàn)refresh方法即可:
1
2
3
4
5
6
|
- (void)refresh {
// 加載數(shù)據(jù)
[self.tableView reloadData];// 重新載入UITableView
[self stopLoading];//停止動畫
}
|
STableViewController 下拉刷新、上拉加載更多
GitHub:https://github.com/shiki/STableViewController
STableViewController比PullToRefresh多了一個上拉加載更多功能,使用上也差不多簡單,需要繼承自STableViewController,再實現(xiàn)一些方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[!--empirenews.page--]33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
- (void) viewDidLoad
{
[super viewDidLoad];
self.title = @"STableViewController Demo";
[self.tableView setBackgroundColor:[UIColor lightGrayColor]];
// 需要創(chuàng)建兩個自定義視圖用于顯示"下拉刷新"、"上拉加載更多"
self.headerView = headerView;
self.footerView = footerView;
}
[!--empirenews.page--]#pragma mark - Pull to Refresh
- (void) pinHeaderView
{
[super pinHeaderView];
// 下拉刷新視圖顯示一些加載動畫
}
- (void) unpinHeaderView
{
[super unpinHeaderView];
// 下拉刷新視圖停止動畫
}
- (void) headerViewDidScroll:(BOOL)willRefreshOnRelease scrollView:(UIScrollView *)scrollView
{
// 下拉刷新視圖顯示狀態(tài)信息
if (willRefreshOnRelease)
//hv.title.text = @"松開后刷新...";
else
//hv.title.text = @"下拉刷新...";
}
- (BOOL) refresh
{
if (![super refresh])
return NO;
// 下拉刷新加載數(shù)據(jù)
[self performSelector:@selector(addItemsOnTop) withObject:nil afterDelay:2.0];
return YES;
}
#pragma mark - Load More
- (void) willBeginLoadingMore
{
// 上拉加載更多視圖加載動畫
}
- (void) loadMoreCompleted
{
[super loadMoreCompleted];
// 上拉加載更多視圖停止動畫
if (!self.canLoadMore) {
//沒有更多數(shù)據(jù)的時候執(zhí)行代碼...
}
}
- (BOOL) loadMore
{
if (![super loadMore])
return NO;
// 上拉加載更多數(shù)據(jù)
[self performSelector:@selector(addItemsOnBottom) withObject:nil afterDelay:2.0];
return YES;
}
//
- (void) addItemsOnTop
{
// 加載數(shù)據(jù)...
[self.tableView reloadData];
[!--empirenews.page--] // 數(shù)據(jù)加載完成通知上拉視圖
[self refreshCompleted];
}
- (void) addItemsOnBottom
{
// 加載更多數(shù)據(jù)...
[self.tableView reloadData];
// 通過判斷設(shè)置是否可以加載更多
//self.canLoadMore = NO;
// 數(shù)據(jù)加載完成通知下拉視圖
[self loadMoreCompleted];
}
|
SVPullToRefresh 下拉刷新、上拉加載更多
GitHub:https://github.com/samvermette/SVPullToRefresh
包含SVPullToRefresh + SVInfiniteScrolling為UITableView提供下拉刷新、上拉加載更多功能。
使用起來也相當(dāng)簡單,只要在UITableViewController里實現(xiàn)以下方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
- (void)viewDidLoad {
[super viewDidLoad];
__weak SVViewController *weakSelf = self;
// 設(shè)置下拉刷新
[self.tableView addPullToRefreshWithActionHandler:^{
[!--empirenews.page--] [weakSelf insertRowAtTop];
}];
// 設(shè)置上拉加載更多
[self.tableView addInfiniteScrollingWithActionHandler:^{
[weakSelf insertRowAtBottom];
}];
}
- (void)viewDidAppear:(BOOL)animated {
[tableView triggerPullToRefresh];
}
- (void)insertRowAtTop {
// 獲取數(shù)據(jù)....
// 停止動畫
[self.tableView.pullToRefreshView stopAnimating];
}
- (void)insertRowAtBottom {
// 獲取數(shù)據(jù)....
// 停止動畫
[weakSelf.tableView.infiniteScrollingView stopAnimating];
}
|
CMPopTipView 提示信息
GitHub:https://github.com/chrismiles/CMPopTipView
CMPopTipView用于在一些視圖上顯示提示信息:
1
2
3
4
5
6
7
8
9
10
|
self.tipView = [[CMPopTipView alloc] initWithMessage:@"提示消息"];
self.tipView.delegate = self;
[self.tipView presentPointingAtView:anyButton inView:self.view animated:YES];// 點擊按鈕顯示
[self.tipView presentPointingAtBarButtonItem:barButtonItem animated:YES];// 點擊導(dǎo)航欄按鈕顯示
#pragma mark CMPopTipViewDelegate methods
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView {
// 清理資源
self.tipView = nil;
}
|
PrettyKit
GitHub:https://github.com/vicpenap/PrettyKit[!--empirenews.page--]
定制了一些UI組件如UITableViewCell、UINavigationBar、UITabBar、UIToolBar等,比系統(tǒng)自帶的更加美觀。
MGBox2
GitHub:https://github.com/sobri909/MGBox2
提供一些定制的UI組件可以更簡單快速的創(chuàng)建表格、網(wǎng)格布局,以及豐富的文本呈現(xiàn),基于block的事件機制等,包含:MGBox、MGTableBox、MGTableBoxStyled、MGScrollView、MGButton、MGEvents、MGEasyFrame、MGLine等,其中MGBox還支持screenshot方法用于截圖。
Nimbus
GitHub:https://github.com/jverkoey/nimbus
著名的框架,提供了一套非常豐富的UI組件,可以使開發(fā)變得更加簡單、有效率。
FlatUIKit
GitHub:https://github.com/Grouper/FlatUIKit
扁平化設(shè)計的UI組件,類似于WP或者iOS7的風(fēng)格。
MUKMediaGallery
GitHub:https://github.com/muccy/MUKMediaGallery
媒體庫效果,支持圖片、視頻及音頻。
PTShowcaseViewController
GitHub:https://github.com/exalted/PTShowcaseViewController
同樣是一個媒體庫效果,支持的格式更多,包括:圖片、視頻、PDF等.
MWPhotoBrowser
GitHub:https://github.com/mwaterfall/MWPhotoBrowser
圖片展示效果,支持本地及遠(yuǎn)程的圖片,使用也比較簡單,只要實現(xiàn)MWPhotoBrowserDelegate協(xié)議:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
@interface TestViewController ()<MWPhotoBrowserDelegate>
{
NSArray *_photos;
}
-(void) doAction {
NSMutableArray *photos = [[NSMutableArray alloc] init];
for (...) {
MWPhoto* photo = [MWPhoto photoWithURL:[NSURL URLWithString:url]];// 設(shè)置圖片地址
[!--empirenews.page--] photo.caption = description;// 設(shè)置描述
[photos addObject:photo];
}
_photos = photos;
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
browser.displayActionButton = YES;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:browser];
nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nc animated:YES];
}
#pragma mark - MWPhotoBrowserDelegate
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
return _photos.count;
}
- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
if (index < _photos.count)
return [_photos objectAtIndex:index];
return nil;
}
|