當(dāng)前位置:首頁 > 嵌入式 > 嵌入式軟件
[導(dǎo)讀] Reachability 檢測網(wǎng)絡(luò)連接ASIHTTPRequest 網(wǎng)絡(luò)請求MBProgressHUD 提示效果SVProgressHUD 提示效果ZAActivityBar 提示效果SBJson JSON解析JSONKit JSON解析SDWebImage 圖片

 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ā)中不可避免的會(huì)用到一些第三方類庫,它們提供了很多實(shí)用的功能,使我們的開發(fā)變得更有效率;同時(shí),也可以從它們的源代碼中學(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的一個(gè)包裝,它提供了一套更加簡潔的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
NSURL *url = [NSURL URLWithString:@" http://allseeing-i.com "];
__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

一般會(huì)在.m文件實(shí)現(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í)行某個(gè)異步請求時(shí)開始調(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--]

請求完成時(shí)隱藏提示效果:

1
[HUD hide:YES];

對于同步方法一般都是用showWhileExecuting方法,方法執(zhí)行完成之后會(huì)自動(dòng)隱藏提示效果:

1
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

SVProgressHUD 提示效果

GitHub:https://github.com/samvermette/SVProgressHUD

SVProgressHUD和MBProgressHUD效果差不多,不過不需要使用協(xié)議,同時(shí)也不需要聲明實(shí)例。

直接通過類方法進(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秒后自動(dòng)隱藏提示(使用的圖標(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使用的動(dòng)畫效果來源于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使用起來稍顯繁瑣,特別是初始化的時(shí)候:

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>
// ...
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

需要注意的是,pladeholderImage的大小一定要大于UIImageView的大小,否則可能不顯示placeholderImage圖片。

它還支持block語法用于在加載完成時(shí)做一些操作:

[!--empirenews.page--]1
2
3
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
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加載圖片時(shí),顯示加載效果(UIActivityIndicatorView實(shí)現(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提供下拉刷新功能的類庫,使用起來稍顯麻煩,需要實(shí)現(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];
}
// 更新最后加載時(shí)間
[_refreshHeaderView refreshLastUpdatedDate];
}
 
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods
 
- (void)reloadTableViewDataSource{
// 在這里加入代碼用于獲取數(shù)據(jù)
_reloading = YES;
}
 
- (void)doneLoadingTableViewData{
// 數(shù)據(jù)加載完成時(shí)調(diào)用這個(gè)方法
_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,再實(shí)現(xiàn)refresh方法即可:

1
2
3
4
5
6
- (void)refresh {
// 加載數(shù)據(jù)
 
[self.tableView reloadData];// 重新載入U(xiǎn)ITableView
[self stopLoading];//停止動(dòng)畫
}

STableViewController 下拉刷新、上拉加載更多

GitHub:https://github.com/shiki/STableViewController

STableViewController比PullToRefresh多了一個(gè)上拉加載更多功能,使用上也差不多簡單,需要繼承自STableViewController,再實(shí)現(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]];
// 需要?jiǎng)?chuàng)建兩個(gè)自定義視圖用于顯示"下拉刷新"、"上拉加載更多"
self.headerView = headerView;
self.footerView = footerView;
}
 
[!--empirenews.page--]#pragma mark - Pull to Refresh
- (void) pinHeaderView
{
[super pinHeaderView];
// 下拉刷新視圖顯示一些加載動(dòng)畫
}
- (void) unpinHeaderView
{
[super unpinHeaderView];
// 下拉刷新視圖停止動(dòng)畫
}
- (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
{
// 上拉加載更多視圖加載動(dòng)畫
}
- (void) loadMoreCompleted
{
[super loadMoreCompleted];
// 上拉加載更多視圖停止動(dòng)畫
if (!self.canLoadMore) {
//沒有更多數(shù)據(jù)的時(shí)候執(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里實(shí)現(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ù)....
// 停止動(dòng)畫
[self.tableView.pullToRefreshView stopAnimating];
}
 
- (void)insertRowAtBottom {
// 獲取數(shù)據(jù)....
// 停止動(dòng)畫
[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];// 點(diǎn)擊按鈕顯示
[self.tipView presentPointingAtBarButtonItem:barButtonItem animated:YES];// 點(diǎn)擊導(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的事件機(jī)制等,包含: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è)計(jì)的UI組件,類似于WP或者iOS7的風(fēng)格。

MUKMediaGallery

GitHub:https://github.com/muccy/MUKMediaGallery

媒體庫效果,支持圖片、視頻及音頻。

PTShowcaseViewController

GitHub:https://github.com/exalted/PTShowcaseViewController

同樣是一個(gè)媒體庫效果,支持的格式更多,包括:圖片、視頻、PDF等.

MWPhotoBrowser

GitHub:https://github.com/mwaterfall/MWPhotoBrowser

圖片展示效果,支持本地及遠(yuǎn)程的圖片,使用也比較簡單,只要實(shí)現(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;
}
本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運(yùn)營商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡稱"軟通動(dòng)力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉