JSPatch 調(diào)用第三方庫(kù)教程.寫看新使用的朋友們當(dāng)案例看看,隨便給自己練練手

感覺不錯(cuò)就Star一下吧:https://github.com/CZXBigBrother/JSPatchUseOtherFramework

JSPatchUseOtherFramework

JSPatch 調(diào)用第三方庫(kù)教程.寫看新使用的朋友們當(dāng)案例看看,隨便給自己練練手

現(xiàn)在已經(jīng)寫了這些Demo AFNetworking MBProgressHUD SDWebImage MJRefresh SAMKeychain Masonry MJExtension
文檔正在編寫中.......(先補(bǔ)上粗略的文檔,詳細(xì)文檔稍后補(bǔ)上)

AFNetworking使用

defineClass('AFNClass: UIViewController', {
  viewDidLoad: function() {
    require('AFHTTPSessionManager,AFNetworking,NSProgress,NSURLSessionDataTask,NSError,AFHTTPResponseSerializer,NSString')
    self.ORIGviewDidLoad();
    self.setTitle("AFNClass")
    self.view().setBackgroundColor(UIColor.grayColor())
   var mgr = AFHTTPSessionManager.manager();
   mgr.setResponseSerializer(AFHTTPResponseSerializer.serializer());
   mgr.GET_parameters_progress_success_failure("https://www.baidu.com", null, block('NSProgress*', function(downloadProgress) {}), block("NSURLSessionDataTask*, id", function(task, responseObject) {
       console.log("success = %@", NSString.alloc().initWithData_encoding(responseObject,4));
   }), block("NSURLSessionDataTask*, NSError*", function(task, error) {
       console.log("failure = %@", error);
   }));
  },
})

MBProgressHUD使用

defineClass('MBPClass:UIViewController',{
  viewDidLoad: function() {
    self.ORIGviewDidLoad();
    self.setTitle("MBPClass")
    self.view().setBackgroundColor(UIColor.grayColor())

    require('MBProgressHUD')
    MBProgressHUD.showHUDAddedTo_animated(self.view(),YES)
  },
})

SDWebImage使用

defineClass('SDWebClass:UIViewController',{
  viewDidLoad: function() {
    require('UIImageView,NSURL')
    self.ORIGviewDidLoad();
    self.setTitle("SDWebClass")
    self.view().setBackgroundColor(UIColor.grayColor())
    var imgBackground = UIImageView.alloc().initWithFrame(self.view().frame())
    self.view().addSubview(imgBackground)
    imgBackground.sd__setImageWithURL(NSURL.URLWithString("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png"))
  },
})

MJRefresh使用

defineClass('MJRefreshClass:UIViewController<UITableViewDelegate,UITableViewDataSource>',['myTableView'],{
  viewDidLoad: function() {
    self.ORIGviewDidLoad();
    require('MJRefreshNormalHeader,MJRefreshBackNormalFooter,MJRefresh')
    self.setTitle("MJRefreshClass")
    self.view().setBackgroundColor(UIColor.grayColor())
    var tableView = UITableView.alloc().initWithFrame_style(self.view().frame(),0)
    tableView.setDelegate(self)
    tableView.setDataSource(self)
    self.view().addSubview(tableView)
    tableView.setMj__header(MJRefreshNormalHeader.headerWithRefreshingTarget_refreshingAction(self,"startFresh"))
    tableView.setMj__footer(MJRefreshBackNormalFooter.footerWithRefreshingTarget_refreshingAction(self,"footFreshL"))
    self.setMyTableView(tableView)
  },
  numberOfSectionsInTableView: function(tableView) {
    return 1;
  },
  tableView_numberOfRowsInSection: function(tableView, section) {
    return 20;
  },
  tableView_cellForRowAtIndexPath: function(tableView, indexPath) {
    var cell = tableView.dequeueReusableCellWithIdentifier("cell") 
    if (!cell) {
      cell = require('UITableViewCell').alloc().initWithStyle_reuseIdentifier(0, "cell")
    }
    cell.textLabel().setText('123')
    return cell
  },
  tableView_heightForRowAtIndexPath: function(tableView, indexPath) {
    return 44
  },
  startFresh:function() {
    console.log("start")
    var weakSelf = __weak(self)
    dispatch_after(1.0, function(){
        weakSelf.myTableView().mj__header().endRefreshing();
    })
  },
  footFreshL:function() {
    console.log("foot")
    var weakSelf = __weak(self)
    dispatch_after(1.0, function(){
        weakSelf.myTableView().mj__footer().endRefreshing();
    })
  },
})

SAMKeychain使用

defineClass('SAMKeychainClass:UIViewController',{
  viewDidLoad: function() {
    require('SAMKeychain')
    self.ORIGviewDidLoad();
    self.setTitle("SAMKeychainClass")
    self.view().setBackgroundColor(UIColor.grayColor())
    SAMKeychain.setPassword_forService_account("password","service","account")
    console.log(SAMKeychain.allAccounts())
    console.log(SAMKeychain.passwordForService_account("service","account"))
  },
})

Masonry使用

defineClass('MasonryClass:UIViewController',{
  viewDidLoad: function() {
    require('UIView,MASConstraint,MASConstraintMaker')
    self.ORIGviewDidLoad();
    self.setTitle("MasonryClass")
    self.view().setBackgroundColor(UIColor.grayColor())
    var testView = UIView.alloc().init()
    self.view().addSubview(testView)
    testView.setBackgroundColor(UIColor.redColor())
    testView.mas__makeConstraints(block("MASConstraintMaker*",function(make){
      make.top().equalTo()(self.view())
      make.right().equalTo()(self.view())
      make.left().equalTo()(self.view())
      make.bottom().equalTo()(self.view())
    }))
    var testView2 = UIView.alloc().init();
    self.view().addSubview(testView2);
    testView2.setBackgroundColor(UIColor.greenColor())
    testView2.mas__makeConstraints(block("MASConstraintMaker*",function(make){
      make.top().equalTo()(testView.mas__topMargin()).offset()(100)
      make.right().equalTo()(testView.mas__rightMargin());
      make.left().equalTo()(testView.mas__leftMargin());
      make.height().equalTo()(50)
    }))
  },
})

MJExtension使用

defineClass('testModel:NSObject',['key1','key2'],{

})
defineClass('MJExtensionClass:UIViewController',{
  viewDidLoad: function() {
    self.ORIGviewDidLoad();
    self.setTitle("MJExtensionClass")
    self.view().setBackgroundColor(UIColor.grayColor())
    require('testModel')
    var test = {
      "key1": "value1",
      "key2": "values"
    };
    var model = testModel.mj__objectWithKeyValues(test)
    console.log(model.key1())
    console.log(model.key2())
  },
})
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容