JSPatch OC 您所在的位置:网站首页 oc官网地址 JSPatch OC

JSPatch OC

2023-03-13 12:54| 来源: 网络整理| 查看: 265

今天学习了一个例子,参考地址:http://blog.csdn.net/chenyblog/article/details/50537866

直接上代码了:

// ”导入头文件“require("UIView, UILayer, UIButton, UILabel, UIColor, UITextField, UIFont,UIAlertView");defineClass('ViewController : ViewController ', { viewDidLoad:function(){ self.ORIGviewDidLoad(); // 全局变量 index index = (function () { var counter = 0; return function () {return counter += 1;} })(); // Objective-C 里的常量不能直接在 JS 上使用,可以直接在 JS 上用具体值代替,或者在 JS 上重新定义同名的全局变量 UITextBorderStyleNone = 0; UITextBorderStyleLine = 1; UITextBorderStyleBezel = 2; UITextBorderStyleRoundedRect = 3; // 全局变量 btn = null; txfName = null; lblDesc = null; persent = 0.5; screenWidth = self.view().bounds().width; // 获取控制器中的属性 // 设置UI setupUI(); }, touchesBegan_withEvent:function(touches, event) { txfName.resignFirstResponder(); // var btn = btn1;//self.view().viewWithTag(1000); var i = index(); btn.setTitle_forState('' + i, 0); btn.setTag(i+1000); }, // 自定义的方法命名不能加下划线!!! btnClick:function(sender) { var tag = sender.tag(); var alert = UIAlertView.alloc().initWithTitle_message_delegate_cancelButtonTitle_otherButtonTitles("提示", "按钮的tag为 " + (parseInt(tag)-1000), self, "确定", null); alert.show(); }, alertView_clickedButtonAtIndex:function(alertView, buttonIndex) { console.log("buttonIndex=" + buttonIndex); }, textChange:function(sender) { //此处需将oc字符串转为js字符再进行赋值 var str = sender.text().toJS(); console.log('textChange = ' + str); lblDesc.setText(' ' + str); }})function setupUI() { var i = index(); var cornerRadius = 5; var margin = 8; var x = 0; var width = screenWidth - 2 * x; var height = 100; var margin16 = 16; var y = (height + margin) * 1; // 此处应该 * i var view = UIView.alloc().initWithFrame({x:x, y:y, width:width, height:height}); view.setBackgroundColor(UIColor.greenColor()); self.view().addSubview(view); // 创建文本框 txfName = UITextField.alloc().init(); txfName.setBorderStyle(UITextBorderStyleRoundedRect); var txfX = margin; var txfY = margin; var txfW = screenWidth * persent; var txfH = 35; var txfF = {x:txfX, y:txfY, width:txfW, height:txfH}; txfName.setFrame(txfF); console.log("frame=" + txfName.frame()); // 监听文本框值变化事件 txfName.addTarget_action_forControlEvents(self, 'textChange:', 1


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有