zoukankan      html  css  js  c++  java
  • 【转】iOS开发常用的第三方类库

    原文: http://blog.csdn.net/xiazailushang/article/details/9716043

    在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使我们的开发变得更有效率;同时,也可以从它们的源代码中学习到很多有用的东西。

    Reachability 检测网络连接

    用来检查网络连接是否可用:包括WIFI和WWAN(3G/EDGE/CDMA等)两种工作模式。

    可以从Apple网站下载到:http://developer.apple.com/library/ios/#samplecode/Reachability/History/History.html#//apple_ref/doc/uid/DTS40007324-RevisionHistory-DontLinkElementID_1

    现在有更好的替代品:https://github.com/tonymillion/Reachability,比Apple提供的兼容性更好,而且更加好用,更具体的使用方法请看它提供的例子。

     

    1. <font color="rgb(51, 51, 51)">Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
    2. reach.reachableBlock = ^(Reachability*reach) {
    3.     NSLog(@"网络可用!");
    4. };
    5. reach.unreachableBlock = ^(Reachability*reach) {
    6.     NSLog(@"网络不可用!");
    7. };
    8. // 开始监听
    9. [reach startNotifier];</font>
    复制代码

    ASIHTTPRequest 网络请求ASIHTTPRequest是对CFNetwork API的一个包装,它提供了一套更加简洁的API,使用起来也更加简单。
    官方网站:http://allseeing-i.com/ASIHTTPRequest/
    GitHub:https://github.com/pokeb/asi-http-request
    它不仅仅支持基本的HTTP请求,而且支持基于REST的服务(GET/POST/PUT/DELETE)。最让人喜欢的是,它支持block语法:

    1. NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
    2. __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    3. [request setCompletionBlock:^{
    4.    // Use when fetching text data
    5.    NSString *responseString = [request responseString];

    6.    // Use when fetching binary data
    7.    NSData *responseData = [request responseData];
    8. }];
    9. [request setFailedBlock:^{
    10.    NSError *error = [request error];
    11. }];
    12. [request startAsynchronous];
    复制代码

    它的ASIFormDataRequest子类可以横容易的提交表单数据和文件:

    1. ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    2. [request setPostValue:@"Ben" forKey:@"first_name"];
    3. [request setPostValue:@"Copsey" forKey:@"last_name"];
    4. // Upload a file on disk
    5. [request setFile:@"/Users/ben/Desktop/ben.jpg" withFileName:@"myphoto.jpg" andContentType:@"image/jpeg"
    6. forKey:@"photo"]; 
    7. // Upload an NSData instance
    8. [request setData:imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
    复制代码

    详细的使用方法请下载相应的源代码及例子,或者从官方的使用说明http://allseeing-i.com/ASIHTTPRequest/How-to-use开始。 

    MBProgressHUD 提示效果支持各种状态加载的提示效果,以及带进度的提示效果。
    GitHub:https://github.com/matej/MBProgressHUD
    一般会在.m文件实现MBProgressHUDDelegate协议,并声明HUD变量:

    1. @interface SampleViewController ()<MBProgressHUDDelegate>
    2. {
    3.     MBProgressHUD *HUD;
    4. }
    5. #pragma mark -
    6. #pragma mark MBProgressHUDDelegate methods

    7. - (void)hudWasHidden:(MBProgressHUD *)hud {
    8.   // Remove HUD from screen when the HUD was hidded
    9.   [HUD removeFromSuperview];
    10.   HUD = nil;
    11. }
    复制代码

    在执行某个异步请求时开始调用:

    1. HUD = [MBProgressHUD showHUDAddedTo:self.webView animated:YES];
    2. HUD.labelText = @"正在请求...";
    3. // mode参数可以控制显示的模式
    4. //HUD.mode = MBProgressHUDModeText;
    5. HUD.delegate = self;
    复制代码

    请求完成时隐藏提示效果:

    1. [HUD hide:YES];
    复制代码

    对于同步方法一般都是用showWhileExecuting方法,方法执行完成之后会自动隐藏提示效果:

    1. [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
    复制代码

    SVProgressHUD 提示效果
    GitHub:https://github.com/samvermette/SVProgressHUD
    SVProgressHUD和MBProgressHUD效果差不多,不过不需要使用协议,同时也不需要声明实例。直接通过类方法进行调用即可:

    1. [SVProgressHUD method]
    复制代码

    可以使用以下方法来显示状态:

    1. + (void)show;
    2. + (void)showWithMaskType:(SVProgressHUDMaskType)maskType;
    3. + (void)showWithStatus:(NSString*)string;
    4. + (void)showWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;
    复制代码

    如果需要明确的进度,则使用以下方法:

    1. + (void)showProgress:(CGFloat)progress;
    2. + (void)showProgress:(CGFloat)progress status:(NSString*)status;
    3. + (void)showProgress:(CGFloat)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
    复制代码

    通过dismiss方法来隐藏提示:

    1. + (void)dismiss;
    复制代码

    另外提供了以下方法用于显示状态,并在1秒后自动隐藏提示(使用的图标来源于Glyphish:http://www.glyphish.com/):

    1. + (void)showSuccessWithStatus:(NSString*)string;
    2. + (void)showErrorWithStatus:(NSString *)string;
    3. + (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),成功、失败的状态图标来源于Pictos(http://pictos.cc/)。显示加载状态:

    1. [ZAActivityBar showWithStatus:@"加载中..."];
    复制代码

    显示成功、失败状态:

    1. [ZAActivityBar showSuccessWithStatus:@"成功!"];
    2. [ZAActivityBar showErrorWithStatus:@"失败!"];
    复制代码

    隐藏提示:

    1. [ZAActivityBar dismiss];
    复制代码

    SBJson JSON解析官方: http://sbjson.org/
    GitHub:https://github.com/stig/json-framework
    API使用起来稍显繁琐,特别是初始化的时候:

    1. @interface TestViewController ()<SBJsonStreamParserAdapterDelegate> {
    2.     SBJsonStreamParser *parser;
    3.     SBJsonStreamParserAdapter *adapter;
    4. }

    5. // 冗长的初始化方法足以吓到一大片人
    6. - (void)initSBJSON
    7. {
    8.     // We don't want *all* the individual messages from the
    9.   // SBJsonStreamParser, just the top-level objects. The stream
    10.   // parser adapter exists for this purpose.
    11.   adapter = [[SBJsonStreamParserAdapter alloc] init];
    12.    
    13.   // Set ourselves as the delegate, so we receive the messages
    14.   // from the adapter.
    15.   adapter.delegate = self;
    16.    
    17.   // Create a new stream parser..
    18.   parser = [[SBJsonStreamParser alloc] init];
    19.    
    20.   // .. and set our adapter as its delegate.
    21.   parser.delegate = adapter;
    22.    
    23.   // Normally it's an error if JSON is followed by anything but
    24.   // whitespace. Setting this means that the parser will be
    25.   // expecting the stream to contain multiple whitespace-separated
    26.   // JSON documents.
    27.   parser.supportMultipleDocuments = YES;
    28. }

    29. #pragma mark SBJsonStreamParserAdapterDelegate methods

    30. - (void)parser:(SBJsonStreamParser *)parser foundArray:(NSArray *)array {
    31.     [NSException raise:@"unexpected" format:@"Should not get here"];
    32. }

    33. - (void)parser:(SBJsonStreamParser *)parser foundObject:(NSDictionary *)dict {
    34.     NSLog(@"SBJson parser foundObject");
    35.     // 处理返回的数据
    36. }

    37. // 使用ASIHTTPRequest请求测试
    38. - (void) loadData {
    39.     __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    40.     [request setRequestMethod:@"POST"];
    41.     [request setCompletionBlock:^{
    42.         // Use when fetching text data
    43.         //NSString *responseString = [request responseString];
    44.         // Use when fetching binary data
    45.         NSData *responseData = [request responseData];
    46.         NSLog(@"Connection didReceiveData of length: %u", responseData.length);
    47.          
    48.         // Parse the new chunk of data. The parser will append it to
    49.         // its internal buffer, then parse from where it left off in
    50.         // the last chunk.
    51.         SBJsonStreamParserStatus status = [parser parse:responseData];
    52.          
    53.         if (status == SBJsonStreamParserError) {
    54.             NSLog(@"Parser error: %@", parser.error);
    55.         } else if (status == SBJsonStreamParserWaitingForData) {
    56.             NSLog(@"Parser waiting for more data");
    57.         }
    58.     }];
    59.     [request setFailedBlock:^{
    60.         NSError *error = [request error];
    61.         NSLog(@"failed - %@ %@", [error localizedDescription], error);
    62.     }];
    63.     [request startAsynchronous];
    64. }
    复制代码

    JSONKit JSON解析
    GitHub:https://github.com/johnezang/JSONKit
    提供比SBJson更优异的性能以及更加简便的使用方法,但是中文最好使用utf-8格式(uXXXX),否则容易造成乱码。API调用起来非常简单,省去了SBJson那么一大堆的方法:

    1. JSONDecoder* decoder = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionNone];
    2. id result = [decoder objectWithData:jsonData];
    复制代码

    详细的使用方法请看它的GitHub主页。
    SDWebImage 图片异步加载及缓存
    SDWebImage用于异步下载网络上的图片,并支持对图片的缓存等。多数情况下是使用UIImageView+WebCache为UIImageView异步加载图片:

    1. #import <SDWebImage/UIImageView+WebCache.h>
    2. // ...
    3. [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
    4.                    placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    复制代码

    需要注意的是,pladeholderImage的大小一定要大于UIImageView的大小,否则可能不显示placeholderImage图片。它还支持block语法用于在加载完成时做一些操作:

    1. [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
    2.                placeholderImage:[UIImage imageNamed:@"placeholder.png"]
    3.                       completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {... completion code here ...}];
    复制代码

    SDWebImage并不局限于UIImageView上,使用SDWebImageManager完成更多的操作:

    1. SDWebImageManager *manager = [SDWebImageManager sharedManager];
    2. [manager downloadWithURL:imageURL
    3.                  options:0
    4.                  progress:^(NSUInteger receivedSize, long long expectedSize)
    5.                  {
    6.                      // 下载进度
    7.                  }
    8.                  completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
    9.                  {
    10.                      if (image)
    11.                      {
    12.                          // 下载完成
    13.                      }
    14.                  }];
    复制代码

    或者使用Image Downloader也是一样的效果:

    1. [SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
    2.         options:0
    3.        progress:^(NSUInteger receivedSize, long long expectedSize)
    4.        {
    5.            // 进度
    6.        }
    7.        completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
    8.        {
    9.            if (image && finished)
    10.            {
    11.                // 下载完成
    12.            }
    13.        }];
    复制代码

    UIActivityIndicator-for-SDWebImage 为SDWebImage显示加载效果
    GitHub:https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage
    用于为SDWebImage在UIImageView加载图片时,显示加载效果(UIActivityIndicatorView实现),它提供以下方法:

    1. - (void)setImageWithURL:(NSURL *)url usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
    2. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
    3. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
    4. - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
    5. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
    6. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
    7. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)activityStyle;
    复制代码

    UIImage+Resize 调整图片大小
    GitHub:https://github.com/coryalder/UIImage_Resize
    提供多种方法为图片设置透明度、圆角、裁剪、调整大小等:

    1. - (UIImage *)imageWithAlpha;
    2. - (UIImage *)transparentBorderImage:(NSUInteger)borderSize;
    3. - (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize;
    4. - (UIImage *)croppedImage:(CGRect)bounds;
    5. - (UIImage *)thumbnailImage:(NSInteger)thumbnailSize
    6.           transparentBorder:(NSUInteger)borderSize
    7.                cornerRadius:(NSUInteger)cornerRadius
    8.        interpolationQuality:(CGInterpolationQuality)quality;
    9. - (UIImage *)resizedImage:(CGSize)newSize
    10.      interpolationQuality:(CGInterpolationQuality)quality;
    11. - (UIImage *)
    12.   resizedImageWithContentMode:(UIViewContentMode)contentMode
    13.                        bounds:(CGSize)bounds
    14.          interpolationQuality:(CGInterpolationQuality)quality;
    复制代码

    更详细使用见:http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/ 
    ImageCacheResize 异步加载图片、缓存及调整大小
    GitHub:https://github.com/toptierlabs/ImageCacheResize
    整合了SDWebImage和UIImage+Resize的功能,用于图片的异步加载、缓存、以及下载完成后调整大小并显示在UIImageView上。提供了以下API用于加载图片以及加载完成后调整图片大小:

    1. - (void)setImageWithURL:(NSURL *)url andCropToBounds:(CGRect)bounds;
    2. - (void)setImageWithURL:(NSURL *)url andResize:(CGSize)size withContentMode:(UIViewContentMode)mode;
    3. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder andCropToBounds:(CGRect)bounds;
    4. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options  andResize:(CGSize)size;
    5. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options  andResize:(CGSize)size withContentMode:(UIViewContentMode)mode;
    6. - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options  andCropToBounds:(CGRect)bounds;
    复制代码

    使用方法和SDWebImage一样简单,如以下官方例子:

    1. [imageview setImageWithURL:[NSURL URLWithString:@"http://t0.gstatic.com/images?q=tbn:ANd9GcQfraHpiabjEY8iDdBe9OUQYHMtwfuAv9ZRR0RYKuoVF_EpE8Fp5A"] andResize:CGSizeMake(30, 30) withContentMode:UIViewContentModeScaleAspectFit]; // 按比例缩放
    2. [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
    这是最早出现的为UITableView提供下拉刷新功能的类库,使用起来稍显麻烦,需要实现诸多协议(代码取自官方DEMO):

    1. #import "EGORefreshTableHeaderView.h"

    2. @interface RootViewController : UITableViewController  <EGORefreshTableHeaderDelegate, UITableViewDelegate, UITableViewDataSource>{
    3.   EGORefreshTableHeaderView *_refreshHeaderView;
    4.   //  是否正在加载中 
    5.   BOOL _reloading;
    6. }

    7. - (void)viewDidLoad {
    8.     [super viewDidLoad];
    9.      
    10.   if (_refreshHeaderView == nil) {
    11.     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)];
    12.     view.delegate = self;
    13.     [self.tableView addSubview:view];
    14.     _refreshHeaderView = view;
    15.     [view release];
    16.   }
    17.   //  更新最后加载时间
    18.   [_refreshHeaderView refreshLastUpdatedDate];
    19. }

    20. #pragma mark -
    21. #pragma mark Data Source Loading / Reloading Methods

    22. - (void)reloadTableViewDataSource{
    23.   //  在这里加入代码用于获取数据
    24.   _reloading = YES;
    25. }

    26. - (void)doneLoadingTableViewData{
    27.   //  数据加载完成时调用这个方法
    28.   _reloading = NO;
    29.   [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
    30. }

    31. #pragma mark -
    32. #pragma mark UIScrollViewDelegate Methods

    33. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 
    34.   [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    35. }

    36. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    37.   [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    38. }

    39. #pragma mark -
    40. #pragma mark EGORefreshTableHeaderDelegate Methods

    41. - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    42.   [self reloadTableViewDataSource];
    43.   [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    44. }

    45. - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    46.   return _reloading; // should return if data source model is reloading
    47. }

    48. - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    49.   return [NSDate date]; // should return date data source was last changed
    50. }
    复制代码

    PullToRefresh 下拉刷新
    GitHub:https://github.com/leah/PullToRefresh
    PullToRefresh提供比EGOTableViewPullRefresh更加简单的使用方法,只要继承自PullRefreshTableViewController,再实现refresh方法即可:

    1. - (void)refresh {
    2.     // 加载数据

    3.     [self.tableView reloadData]; // 重新载入UITableView
    4.     [self stopLoading]; //停止动画
    5. }
    复制代码

    STableViewController  下拉刷新、上拉加载更多
    GitHub:https://github.com/shiki/STableViewController
    STableViewController比PullToRefresh多了一个上拉加载更多功能,使用上也差不多简单,需要继承自STableViewController,再实现一些方法:

    1. - (void) viewDidLoad
    2. {
    3.   [super viewDidLoad];
    4.    
    5.   self.title = @"STableViewController Demo";
    6.   [self.tableView setBackgroundColor:[UIColor lightGrayColor]];
    7.    
    8.   // 需要创建两个自定义视图用于显示"下拉刷新"、"上拉加载更多"
    9.   self.headerView = headerView;  
    10.   self.footerView = footerView;  
    11. }

    12. #pragma mark - Pull to Refresh
    13. - (void) pinHeaderView
    14. {
    15.   [super pinHeaderView];
    16.    
    17.   // 下拉刷新视图显示一些加载动画
    18. }
    19. - (void) unpinHeaderView
    20. {
    21.   [super unpinHeaderView];
    22.    
    23.   // 下拉刷新视图停止动画
    24. }
    25. - (void) headerViewDidScroll:(BOOL)willRefreshOnRelease scrollView:(UIScrollView *)scrollView
    26. {
    27.   // 下拉刷新视图显示状态信息
    28.   if (willRefreshOnRelease)
    29.     //hv.title.text = @"松开后刷新...";
    30.   else
    31.     //hv.title.text = @"下拉刷新...";
    32. }

    33. - (BOOL) refresh
    34. {
    35.   if (![super refresh])
    36.     return NO;
    37.    
    38.   // 下拉刷新加载数据
    39.   [self performSelector:@selector(addItemsOnTop) withObject:nil afterDelay:2.0];
    40.   return YES;
    41. }

    42. #pragma mark - Load More
    43. - (void) willBeginLoadingMore
    44. {
    45.   // 上拉加载更多视图加载动画
    46. }
    47. - (void) loadMoreCompleted
    48. {
    49.   [super loadMoreCompleted];
    50.   // 上拉加载更多视图停止动画
    51.    
    52.   if (!self.canLoadMore) {
    53.     //没有更多数据的时候执行代码...
    54.   }
    55. }

    56. - (BOOL) loadMore
    57. {
    58.   if (![super loadMore])
    59.     return NO;
    60.    
    61.   // 上拉加载更多数据
    62.   [self performSelector:@selector(addItemsOnBottom) withObject:nil afterDelay:2.0];
    63.   return YES;
    64. }

    65. // 
    66. - (void) addItemsOnTop
    67. {
    68.   // 加载数据...
    69.    
    70.   [self.tableView reloadData];  
    71.   // 数据加载完成通知上拉视图
    72.   [self refreshCompleted];
    73. }

    74. - (void) addItemsOnBottom
    75. {
    76.   // 加载更多数据...
    77.   [self.tableView reloadData];
    78.    
    79.   // 通过判断设置是否可以加载更多
    80.   //self.canLoadMore = NO;  
    81.   // 数据加载完成通知下拉视图
    82.   [self loadMoreCompleted];
    83. }
    复制代码

    SVPullToRefresh 下拉刷新、上拉加载更多
    GitHub:https://github.com/samvermette/SVPullToRefresh
    包含SVPullToRefresh + SVInfiniteScrolling为UITableView提供下拉刷新、上拉加载更多功能。使用起来也相当简单,只要在UITableViewController里实现以下方法:

    1. - (void)viewDidLoad {
    2.     [super viewDidLoad];

    3.     __weak SVViewController *weakSelf = self;
    4.      
    5.     // 设置下拉刷新
    6.     [self.tableView addPullToRefreshWithActionHandler:^{
    7.         [weakSelf insertRowAtTop];
    8.     }];
    9.          
    10.     // 设置上拉加载更多
    11.     [self.tableView addInfiniteScrollingWithActionHandler:^{
    12.         [weakSelf insertRowAtBottom];
    13.     }];
    14. }

    15. - (void)viewDidAppear:(BOOL)animated {
    16.     [tableView triggerPullToRefresh];
    17. }

    18. - (void)insertRowAtTop {
    19.     // 获取数据....
    20.      
    21.     // 停止动画
    22.     [self.tableView.pullToRefreshView stopAnimating];
    23. }

    24. - (void)insertRowAtBottom {
    25.     // 获取数据....
    26.      
    27.     // 停止动画
    28.     [weakSelf.tableView.infiniteScrollingView stopAnimating];
    29. }
    复制代码

    CMPopTipView 提示信息
    GitHub:https://github.com/chrismiles/CMPopTipView
    CMPopTipView用于在一些视图上显示提示信息:

    1. self.tipView = [[CMPopTipView alloc] initWithMessage:@"提示消息"];
    2. self.tipView.delegate = self;
    3. [self.tipView presentPointingAtView:anyButton inView:self.view animated:YES]; // 点击按钮显示
    4. [self.tipView presentPointingAtBarButtonItem:barButtonItem animated:YES]; // 点击导航栏按钮显示
    5.      
    6. #pragma mark CMPopTipViewDelegate methods
    7. - (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView {
    8.   // 清理资源
    9.   self.tipView = nil;
    10. }
    复制代码

    PrettyKit
    GitHub:https://github.com/vicpenap/PrettyKit
    定制了一些UI组件如UITableViewCell、UINavigationBar、UITabBar、UIToolBar等,比系统自带的更加美观。 

    MGBox2
    GitHub:https://github.com/sobri909/MGBox2
    提供一些定制的UI组件可以更简单 快速的创建表格、网格布局,以及丰富的文本呈现,基于block的事件机制等,包含:MGBox、MGTableBox、 MGTableBoxStyled、MGScrollView、MGButton、MGEvents、MGEasyFrame、MGLine等,其中 MGBox还支持screenshot方法用于截图。

    Nimbus
    GitHub:https://github.com/jverkoey/nimbus
    著名的框架,提供了一套非常丰富的UI组件,可以使开发变得更加简单、有效率。

    FlatUIKit
    GitHub:https://github.com/Grouper/FlatUIKit
    扁平化设计的UI组件,类似于WP或者iOS7的风格。

    MUKMediaGallery
    GitHub:https://github.com/muccy/MUKMediaGallery
    体库效果,支持图片、视频及音频。

    PTShowcaseViewController
    GitHub:https://github.com/exalted/PTShowcaseViewController
    同样是一个媒体库效果,支持的格式更多,包括:图片、视频、PDF等. 

    MWPhotoBrowser
    GitHub:https://github.com/mwaterfall/MWPhotoBrowser
    图片展示效果,支持本地及远程的图片,使用也比较简单,只要实现MWPhotoBrowserDelegate协议:

    1. @interface TestViewController ()<MWPhotoBrowserDelegate>
    2. {
    3.     NSArray *_photos;
    4. }

    5. -(void) doAction {
    6.         NSMutableArray *photos = [[NSMutableArray alloc] init];
    7.         for (...) {
    8.             MWPhoto* photo = [MWPhoto photoWithURL:[NSURL URLWithString:url]]; // 设置图片地址
    9.             photo.caption = description; // 设置描述
    10.             [photos addObject:photo];
    11.         }
    12.         _photos = photos;
    13.         MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    14.         browser.displayActionButton = YES;
    15.          
    16.         UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:browser];
    17.         nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    18.         [self presentModalViewController:nc animated:YES];
    19. }

    20. #pragma mark - MWPhotoBrowserDelegate

    21. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    22.     return _photos.count;
    23. }

    24. - (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    25.     if (index < _photos.count)
    26.         return [_photos objectAtIndex:index];
    27.     return nil;
    28. }
    复制代码

    ios-image-filters
    GitHub:https://github.com/esilverberg/ios-image-filters提供多种图片滤镜效果。

    PDF Reader Core for iOS
    GitHub:https://github.com/vfr/Reader
    PDF阅读器核心。 


    DTCoreText
    GitHub:https://github.com/Cocoanetics/DTCoreText
    支持富文本的显示如HTML。

    FTCoreText
    GitHub:https://github.com/FuerteInternational/FTCoreText
    富文本视图 

    CoreTextWrapper
    GitHub:https://github.com/akosma/CoreTextWrapper
    支持多列的文本视图 

    Base64
    GitHub:https://github.com/nicklockwood/Base64
    提供对字符串的Base64编码 


    RNCryptor
    GitHub:https://github.com/rnapier/RNCryptor提供AES加密方法

  • 相关阅读:
    window安装swagger editor
    DiffMerge安装配置使用
    线程池相关知识点
    JAVA程序员面试笔试宝典4
    JAVA程序员面试笔试宝典3
    JAVA程序员面试笔试宝典2
    JAVA程序员面试笔试宝典1
    Linux开启ssh服务
    面试题
    java基础学习之垃圾回收机制
  • 原文地址:https://www.cnblogs.com/A--G/p/4779759.html
Copyright © 2011-2022 走看看