iOS開發常用的第三方類庫


在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提供的兼容性更好,而且更加好用,更具體的使用方法請看它提供的例子。

Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
reach.reachableBlock = ^(Reachability*reach) {
    NSLog(@"網絡可用!");
};
reach.unreachableBlock = ^(Reachability*reach) {
    NSLog(@"網絡不可用!");
};
// 開始監聽
[reach startNotifier];

 

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語法:

   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子類可以橫容易的提交表單數據和文件:

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"];

詳細的使用方法請下載相應的源代碼及例子,或者從官方的使用說明http://allseeing-i.com/ASIHTTPRequest/How-to-use開始。

 

MBProgressHUD 提示效果

支持各種狀態加載的提示效果,以及帶進度的提示效果。

GitHub:https://github.com/matej/MBProgressHUD

一般會在.m文件實現MBProgressHUDDelegate協議,並聲明HUD變量:

@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;
}

在執行某個異步請求時開始調用:

    HUD = [MBProgressHUD showHUDAddedTo:self.webView animated:YES];
    HUD.labelText = @"正在請求...";
    // mode參數可以控制顯示的模式
    //HUD.mode = MBProgressHUDModeText;
    HUD.delegate = self;

請求完成時隱藏提示效果:

[HUD hide:YES];

對於同步方法一般都是用showWhileExecuting方法,方法執行完成之后會自動隱藏提示效果:

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

 

SVProgressHUD 提示效果

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

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

直接通過類方法進行調用即可:

[SVProgressHUD method]

可以使用以下方法來顯示狀態:

+ (void)show;
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType;
+ (void)showWithStatus:(NSString*)string;
+ (void)showWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;

如果需要明確的進度,則使用以下方法:

+ (void)showProgress:(CGFloat)progress;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;

通過dismiss方法來隱藏提示:

+ (void)dismiss;

另外提供了以下方法用於顯示狀態,並在1秒后自動隱藏提示(使用的圖標來源於Glyphish:http://www.glyphish.com/):

+ (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),成功、失敗的狀態圖標來源於Pictos(http://pictos.cc/)。

顯示加載狀態:

[ZAActivityBar showWithStatus:@"加載中..."];

顯示成功、失敗狀態:

[ZAActivityBar showSuccessWithStatus:@"成功!"];
[ZAActivityBar showErrorWithStatus:@"失敗!"];

隱藏提示:

[ZAActivityBar dismiss];

 

SBJson JSON解析

官方: http://sbjson.org/

GitHub:https://github.com/stig/json-framework

API使用起來稍顯繁瑣,特別是初始化的時候:

@interface TestViewController ()<SBJsonStreamParserAdapterDelegate> {
    SBJsonStreamParser *parser;
    SBJsonStreamParserAdapter *adapter;
}

// 冗長的初始化方法足以嚇到一大片人
- (void)initSBJSON
{
    // 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 {
    [NSException raise:@"unexpected" format:@"Should not get here"];
}

- (void)parser:(SBJsonStreamParser *)parser foundObject:(NSDictionary *)dict {
    NSLog(@"SBJson parser foundObject");
    // 處理返回的數據
}

// 使用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);
        } 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更優異的性能以及更加簡便的使用方法,但是中文最好使用utf-8格式(\uXXXX),否則容易造成亂碼。

API調用起來非常簡單,省去了SBJson那么一大堆的方法:

JSONDecoder* decoder = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionNone];
id result = [decoder objectWithData:jsonData];

詳細的使用方法請看它的GitHub主頁。

 

SDWebImage 圖片異步加載及緩存

SDWebImage用於異步下載網絡上的圖片,並支持對圖片的緩存等。

多數情況下是使用UIImageView+WebCache為UIImageView異步加載圖片:

#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語法用於在加載完成時做一些操作:

[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完成更多的操作:

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
                 options:0
                 progress:^(NSUInteger receivedSize, long long expectedSize)
                 {
                     // 下載進度
                 }
                 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
                 {
                     if (image)
                     {
                         // 下載完成
                     }
                 }];

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

[SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
        options:0
       progress:^(NSUInteger receivedSize, long long expectedSize)
       {
           // 進度
       }
       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實現),它提供以下方法:

- (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;
- (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 調整圖片大小

GitHub:https://github.com/coryalder/UIImage_Resize

提供多種方法為圖片設置透明度、圓角、裁剪、調整大小等:

- (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;

更詳細使用見:http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

注意:這種方法調整圖片大小有可能會產生圖片模糊失真問題(因為不同設備的scale導致)

這里有一個更簡單的方法(http://stackoverflow.com/questions/6141298/how-to-scale-down-a-uiimage-and-make-it-crispy-sharp-at-the-same-time-instead):

- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
    CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
    CGImageRef imageRef = image.CGImage;

    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    // Set the quality level to use when rescaling
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);

    CGContextConcatCTM(context, flipVertical);  
    // Draw into the context; this scales the image
    CGContextDrawImage(context, newRect, imageRef);

    // Get the resized image from the context and a UIImage
    CGImageRef newImageRef = CGBitmapContextCreateImage(context);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

    CGImageRelease(newImageRef);
    UIGraphicsEndImageContext();    

    return newImage;
}

 

ImageCacheResize 異步加載圖片、緩存及調整大小

GitHub:https://github.com/toptierlabs/ImageCacheResize

整合了SDWebImage和UIImage+Resize的功能,用於圖片的異步加載、緩存、以及下載完成后調整大小並顯示在UIImageView上。

提供了以下API用於加載圖片以及加載完成后調整圖片大小:

- (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一樣簡單,如以下官方例子:

[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

這是最早出現的為UITableView提供下拉刷新功能的類庫,使用起來稍顯麻煩,需要實現諸多協議(代碼取自官方DEMO):

#import "EGORefreshTableHeaderView.h"

@interface RootViewController : UITableViewController  <EGORefreshTableHeaderDelegate, UITableViewDelegate, UITableViewDataSource>{
	EGORefreshTableHeaderView *_refreshHeaderView;
	//  是否正在加載中 
	BOOL _reloading;
}

- (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{
	//  在這里加入代碼用於獲取數據
	_reloading = YES;
}

- (void)doneLoadingTableViewData{
	//  數據加載完成時調用這個方法
	_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
}

 

PullToRefresh 下拉刷新

GitHub:https://github.com/leah/PullToRefresh

PullToRefresh提供比EGOTableViewPullRefresh更加簡單的使用方法,只要繼承自PullRefreshTableViewController,再實現refresh方法即可:

- (void)refresh {
    // 加載數據

    [self.tableView reloadData]; // 重新載入UITableView
    [self stopLoading]; //停止動畫
}

 

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

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

STableViewController比PullToRefresh多了一個上拉加載更多功能,使用上也差不多簡單,需要繼承自STableViewController,再實現一些方法:

- (void) viewDidLoad
{
  [super viewDidLoad];
  
  self.title = @"STableViewController Demo";
  [self.tableView setBackgroundColor:[UIColor lightGrayColor]];
  
  // 需要創建兩個自定義視圖用於顯示"下拉刷新"、"上拉加載更多"
  self.headerView = headerView;  
  self.footerView = footerView;  
}

#pragma mark - Pull to Refresh
- (void) pinHeaderView
{
  [super pinHeaderView];
  
  // 下拉刷新視圖顯示一些加載動畫
}
- (void) unpinHeaderView
{
  [super unpinHeaderView];
  
  // 下拉刷新視圖停止動畫
}
- (void) headerViewDidScroll:(BOOL)willRefreshOnRelease scrollView:(UIScrollView *)scrollView
{
  // 下拉刷新視圖顯示狀態信息
  if (willRefreshOnRelease)
    //hv.title.text = @"松開后刷新...";
  else
    //hv.title.text = @"下拉刷新...";
}

- (BOOL) refresh
{
  if (![super refresh])
    return NO;
  
  // 下拉刷新加載數據
  [self performSelector:@selector(addItemsOnTop) withObject:nil afterDelay:2.0];
  return YES;
}

#pragma mark - Load More
- (void) willBeginLoadingMore
{
  // 上拉加載更多視圖加載動畫
}
- (void) loadMoreCompleted
{
  [super loadMoreCompleted];
  // 上拉加載更多視圖停止動畫
  
  if (!self.canLoadMore) {
    //沒有更多數據的時候執行代碼...
  }
}

- (BOOL) loadMore
{
  if (![super loadMore])
    return NO;
  
  // 上拉加載更多數據
  [self performSelector:@selector(addItemsOnBottom) withObject:nil afterDelay:2.0];
  return YES;
}

// 
- (void) addItemsOnTop
{
  // 加載數據...
  
  [self.tableView reloadData];  
  // 數據加載完成通知上拉視圖
  [self refreshCompleted];
}

- (void) addItemsOnBottom
{
  // 加載更多數據...
  [self.tableView reloadData];
  
  // 通過判斷設置是否可以加載更多
  //self.canLoadMore = NO;  
  // 數據加載完成通知下拉視圖
  [self loadMoreCompleted];
}

 

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

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

包含SVPullToRefresh + SVInfiniteScrolling為UITableView提供下拉刷新、上拉加載更多功能。

使用起來也相當簡單,只要在UITableViewController里實現以下方法:

- (void)viewDidLoad {
    [super viewDidLoad];

    __weak SVViewController *weakSelf = self;
    
    // 設置下拉刷新
    [self.tableView addPullToRefreshWithActionHandler:^{
        [weakSelf insertRowAtTop];
    }];
        
    // 設置上拉加載更多
    [self.tableView addInfiniteScrollingWithActionHandler:^{
        [weakSelf insertRowAtBottom];
    }];
}

- (void)viewDidAppear:(BOOL)animated {
    [tableView triggerPullToRefresh];
}

- (void)insertRowAtTop {
    // 獲取數據....
    
    // 停止動畫
    [self.tableView.pullToRefreshView stopAnimating];
}

- (void)insertRowAtBottom {
    // 獲取數據....
    
    // 停止動畫
    [weakSelf.tableView.infiniteScrollingView stopAnimating];
}

 

CMPopTipView 提示信息

GitHub:https://github.com/chrismiles/CMPopTipView

CMPopTipView用於在一些視圖上顯示提示信息:

self.tipView = [[CMPopTipView alloc] initWithMessage:@"提示消息"];
self.tipView.delegate = self;
[self.tipView presentPointingAtView:anyButton inView:self.view animated:YES]; // 點擊按鈕顯示
[self.tipView presentPointingAtBarButtonItem:barButtonItem animated:YES]; // 點擊導航欄按鈕顯示
    
#pragma mark CMPopTipViewDelegate methods
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView {
  // 清理資源
  self.tipView = nil;
}

 

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協議:

@interface TestViewController ()<MWPhotoBrowserDelegate>
{
    NSArray *_photos;
}

-(void) doAction {
        NSMutableArray *photos = [[NSMutableArray alloc] init];
        for (...) {
            MWPhoto* photo = [MWPhoto photoWithURL:[NSURL URLWithString:url]]; // 設置圖片地址
            photo.caption = description; // 設置描述
            [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;
}

 

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加密方法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM