iOS使用swift创建View开发

1:大家想使用混编的话,记住架桥。
2:当项目创建swift的时候,“文件名-swift”里面已经包括了Swift文件和初始化等方法,注意的一点就是当OC调用Swift的时候。直接引用头文件“文件名-swift”就可以,不要添加调用类***swift.h文件,否则文件会出现引用框架出现错误。

import UIKit

class KGCFeedBackView: UIView,UITableViewDataSource,UITableViewDelegate {

/*
 // Only override draw() if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 override func draw(_ rect: CGRect) {
 // Drawing code
 }
 */

let main = UIScreen.main.bounds.size

var mTableView:UITableView!

var testView = UIView()

let arry:[String] = ["为什么中断了学习?","难点没有讲透:","课程进度较慢,看着着急啊","不符合选课时的q期望", "太卡了,等网络好了再回来 :","不习惯在手机上学习","随便进来看看"];

//init Myinit
override init(frame:CGRect){
    super.init(frame:CGRect(x:0, y:0, width:SCREEN_HEIGHT, height:SCREEN_WIDTH));
    self.backgroundColor = UIColor(red:0.36, green:0.34, blue:0.34, alpha:0.70)
    setupSubViews()
    initTableView()
}

//View init
func setupSubViews() {
    testView = UIView(frame:CGRect(x:120, y:20, width:SCREEN_HEIGHT-240, height:SCREEN_WIDTH-40));
    testView.backgroundColor = UIColor.white;
    testView.layer.cornerRadius = 5;
    testView.layer.masksToBounds = true;
    testView.clipsToBounds = true
    testView.isHidden = false
    self.addSubview(testView)
}

//tableView init
func initTableView() {
    mTableView = UITableView(frame:CGRect(x:0, y:0, width:testView.width, height:testView.height))
    mTableView.backgroundColor = UIColor.white
    mTableView.dataSource = self
    mTableView.delegate = self
    testView.addSubview(mTableView)
    mTableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellID")
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return arry.count;
}
//#pramrk -- DataSource
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == 0
    {
        return SCREEN_WIDTH/8.2+13;
    }
    return SCREEN_WIDTH/8.2;
}

//#pramrk -- Delegate
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let indentifier = String(format: "Cell%d%d",indexPath.section,indexPath.row)
    var cell:UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: indentifier)
    if cell == nil {
        cell = UITableViewCell(style: .default, reuseIdentifier: indentifier)
    }
    if indexPath.row == 0 {
        cell.backgroundColor = UIColor(red:0.45, green:0.79, blue:0.25, alpha:1.00)
    }
    cell.textLabel?.text = arry[indexPath.row]
    cell.textLabel?.font = UIFont.systemFont(ofSize: 18);
    cell.textLabel?.textAlignment = NSTextAlignment.center;
    cell.selectionStyle = UITableViewCellSelectionStyle.none
    return cell;
}
//#pramrk -- didSelectRowAt
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.row == 0 {
        return;
    }
    let string:NSString!
    string = String(format:"%d",indexPath.row) as NSString;
    reqeustGangWeiData(Path:string)
}

//FeedBack
func reqeustGangWeiData(Path:NSString) {
    
    print(Path);
    UIApplication.shared.keyWindow?.showLoadingAnimationView()
    Common.postQuestionBankRequest(withUrl:"kgc/app/getPosition", withParm:nil, success: { (respesData:Any) in
        UIApplication.shared.keyWindow?.hidenLoadingAnimationView()
        
    }) { (error:Any) in
        UIApplication.shared.keyWindow?.hidenLoadingAnimationView()
        self.makeToast("网络异常,请稍后重试~", duration:2.0, position:CSToastPositionCenter)
    }
    self.removeFromSuperview()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,150评论 1 32
  • 1. 首先确保电脑和手机在同一个WiFi下; 2. 找到电脑的ip地址; 3. 找到手机当前连接的WiFi的代理设...
    不进则退阅读 2,326评论 0 0
  • 最差的衣服 今天周六,不想编辑,容我偷个懒! 对于孩子的教育我们要做的是:1、鼓励孩子做喜欢做的事情并提供条件并做...
    一粒种子的旅行阅读 219评论 0 0
  • 2017年5月23日 星期二 小雨转多云 今天放学比往常回来的要晚一些,女儿说因为今天有练习广场舞的,所以晚点了...
    仲蕊蕊妈妈阅读 213评论 2 2