iOS开源组件分类总结

2019-10-22 14:46:27 浏览数 (1)

下拉刷新

ZJRefreshControl

ZJRefreshControl

下拉刷新 加载更多

Swift

调用方式

代码语言:javascript复制
//只有下拉刷新
refreshControl = ZJRefreshControl(scrollView: appTableView, refreshBlock: {
        self.dropViewDidBeginRefreshing()
})

//下拉刷新和上拉加载更多
refreshControl = ZJRefreshControl(scrollView: msgTableView,refreshBlock: {
            self.dropViewDidBeginRefreshing();
        },loadmoreBlock: {
            self.dropViewDidBeginLoadmore();
});

//下拉刷新调用的方法
func dropViewDidBeginRefreshing()->Void{
    println("-----刷新数据-----");
    self.delay(1.5, closure: {
        //结束下拉刷新必须调用
      self.refreshControl.endRefreshing();
    });
}

//上拉加载更多调用的方法
func dropViewDidBeginLoadmore()->Void{
    println("-----加载数据-----");
    self.delay(1.5, closure: {
        //结束加载更多必须调用
      self.refreshControl.endLoadingmore();
    });
}

//延迟执行方法
func delay(delay:Double, closure:()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,
            Int64(delay * Double(NSEC_PER_SEC))
        ),
        dispatch_get_main_queue(), closure)
}

图片/视频选择

DNImagePicker

DNImagePicker

图片选择

Objective-C

调用方式

代码语言:javascript复制

//代理 DNImagePickerControllerDelegate

let imagePicker = DNImagePickerController();
imagePicker.imagePickerDelegate = self;
imagePicker.filterType = DNImagePickerFilterType.Photos;
imagePicker.navigationBar.tintColor = UIColor.whiteColor();
self.presentViewController(imagePicker, animated: true, completion: nil);

//代理方法
func dnImagePickerControllerDidCancel(imagePicker: DNImagePickerController!) {
    imagePicker.dismissViewControllerAnimated(true, completion: nil);
}
    
func dnImagePickerController(imagePicker: DNImagePickerController!, sendImages imageAssets: [AnyObject]!, isFullImage fullImage: Bool) {
    
    if(imageAssets.count > 1){
        self.showNoticeErr("只能选择一张图片", time: 1.2);
    }else{
        let dnasset = imageAssets[0] as! DNAsset;
        DNAsset.getALAsset(dnasset, callback: { (alasset) in
            if(alasset != nil){
                let representation =  alasset.defaultRepresentation()
                let image = UIImage(CGImage:representation.fullResolutionImage().takeUnretainedValue())
                let data = ZJ_ImageUtils.imageCompressJPG(image);
            }
        })
    }
}

弹出层

DOAlertController

DOAlertController

弹出确认取消的层

Swift

调用方式

代码语言:javascript复制
let alertController = DOAlertController(title: "新建文件夹", message: "", preferredStyle: .Alert)
alertController.addTextFieldWithConfigurationHandler { textField in
    textField.placeholder = "请输入文件夹的名称";
}
let cancelAction = DOAlertAction(title: "取消", style: .Cancel, handler: nil)
let okAction = DOAlertAction(title: "确认" ,style: .Default) { action in
    
}
alertController.addAction(cancelAction)
alertController.addAction(okAction)
presentViewController(alertController, animated: true, completion: nil)

Sphere Menu

Sphere Menu

弹出按钮菜单

Swift

调用方式

代码语言:javascript复制
//实现代理 DNImagePickerControllerDelegate

func addMenu() {
    let start = UIImage(named: "start")
    let image1 = UIImage(named: "icon_file_menu_folder")
    let image2 = UIImage(named: "icon_file_menu_img")
    let image3 = UIImage(named: "icon_file_menu_movie")
    let images:[UIImage] = [image1!,image2!,image3!]
    menu = SphereMenu(startPoint: CGPointMake(screenWidth-40, screenHeight-100), startImage: start!, submenuImages:images, tapToDismiss:true)
    menu.delegate = self
    self.view.addSubview(menu)
}

//代理方法
func sphereDidSelected(index: Int) {
    if(index == 0){
        chooseFolder();
    }else if(index == 1){
        chooseImage();
    }else if(index == 2){
        chooseVideo();
    }
    
}

//隐藏菜单
self.menu.hideViewToBottom();

//显示菜单
self.menu.showView();

侧滑菜单

RESideMenu

RESideMenu

侧滑菜单

Objective-C

TableViewCell侧滑

MGSwipeTableCell

MGSwipeTableCell

TableViewCell侧滑

Objective-C

调用方式

  • 1 引用头文件
代码语言:javascript复制
//侧滑按钮
#import "MGSwipeButton.h"
#import "MGSwipeTableCell.h"
  • 2 需要侧滑的tableViewCell继承MGSwipeTableCell
  • 3 Controller实现接口MGSwipeTableCellDelegate
  • 4 相关代码
代码语言:javascript复制
func createRightButtons() -> Array<MGSwipeButton>{
    var buttonArray = Array<MGSwipeButton>();
    let titleArray = [
        "",
        //""
    ];
    let iconArray = [
        UIImage(named: "cell_cross.png"),
        //UIImage(named: "cell_menu.png"),
    ];
    let backgroundColorArray = [
        UIColor(red: 1, green: 102/255, blue: 102/255, alpha: 1),
        //UIColor(red: 104/255, green: 187/255, blue: 248/255, alpha: 1),
    ];
    
    let insets = UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 30);
    
    for i in 0  ..< titleArray.count  {
        let button = MGSwipeButton(title: titleArray[i], icon: iconArray[i], backgroundColor: backgroundColorArray[i],insets: insets);
        buttonArray.append(button);
    }
    
    return buttonArray;
}
    
func swipeTableCell(cell: MGSwipeTableCell!, tappedButtonAtIndex index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool {
    if(index == 0){
        let indexPath = tableView.indexPathForCell(cell);
        print("点击了(indexPath)")
    }
    return true;
}
  • 5 cell中调用
代码语言:javascript复制
cell.rightButtons = createRightButtons();
cell.rightSwipeSettings.transition = MGSwipeTransition.Border;
cell.delegate = self;

数据库

SQLiteDB

SQLiteDB

操作Sqlite数据库

Swift

调用方式

代码语言:javascript复制
let db = SQLiteDB.sharedInstance()
let data = db.query("SELECT * FROM customers WHERE name='John'")
let row = data[0]
if let name = row["name"] {
    textLabel.text = name as! String
}

数据请求

Swift数据请求常用的三个库

Alamofire

网络请求库

Swift

SwiftyJSON

转JSON

Swift

Alamofire-SwiftyJSON

方便以上两个组件的结合使用

Swift

0 人点赞