//

//  ViewController.m

//  11 - 投资管理 - 李洪强

//

//  Created by vic fan on 16/4/8.

//  Copyright © 2016年 李洪强. All rights reserved.

//

#define SCREENW [UIScreen mainScreen].bounds.size.width

#define SCREENH [UIScreen mainScreen].bounds.size.height

#import "ViewController.h"

//投资标详情

#import "LHQInvestmentTargetsCtrl.h"

#import "LHQInvestmentManagementCell.h"

#import "LHQInvestmentManagementModel.h"

//已完成

#import "LHQCompletedCtrl.h"

//未满标

#import "LHQNotFullMarkCtrl.h"

@interface ViewController ()<UITabBarControllerDelegate,UITableViewDataSource>

@property(nonatomic)NSMutableArray *dataArr;

@end

@implementation ViewController

-(NSMutableArray *)dataArr

{

if (!_dataArr) {

_dataArr = [[NSMutableArray alloc] init];

}

return _dataArr;

}

- (void)viewDidLoad {

[super viewDidLoad];

self.title = @"投资管理";

//如果tableView启用分组的话。第一组之前会有空白。把空白去掉

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 17)];

[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:64/255.0 green:41/255.0 blue:96/255.0 alpha:1.0]];

[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

[self.tableView registerNib:[UINib nibWithNibName:@"LHQInvestmentManagementCell" bundle:nil] forCellReuseIdentifier:@"LHQInvestmentManagementCell"];

self.tableView.delegate = self;

self.tableView.dataSource = self;

[self createData];

}

//数据

- (void)createData{

//循环给每一个cell里面的数据数组赋值

for (int i=0; i<4; i++) {

LHQInvestmentManagementModel *model = [[LHQInvestmentManagementModel alloc] init];

NSDictionary *dic = [NSDictionary dictionaryWithObjects:@[@"Snip20160415_11",@"世界那么大,我想去看看",@"还款中",@"12000.00",@"3000.00",@"986.12"] forKeys:@[@"stutes",@"title",@"bidStutes",@"assets",@"invest",@"lastone"]];

[model setValuesForKeysWithDictionary:dic];

[self.dataArr addObject:model];

}

//把模型model放到数据数组中

[self.tableView reloadData];

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

// NSLog(@"%zd,%zd",indexPath.section,indexPath.row);

//点击某一行cell跳转到投资标详情

UIStoryboard *CZStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

LHQInvestmentManagementModel *model = self.dataArr[indexPath.section];

//用模型数据给标的状态赋值

//    CZVC.StateLabel = model.bidStutes;

if([model.bidStutes isEqualToString:@"还款中"]){

LHQInvestmentTargetsCtrl *CZVC = [CZStoryboard instantiateViewControllerWithIdentifier:@"LHQInvestmentTargetsCtrl"];

CZVC.StateLabel = model.bidStutes;

[self.navigationController pushViewController:CZVC animated:YES];

}else if ([model.bidStutes isEqualToString:@"已还款"]){

LHQCompletedCtrl *CVC = [CZStoryboard instantiateViewControllerWithIdentifier:@"LHQCompletedCtrl"];

CVC.StateLabel2 = model.bidStutes;

[self.navigationController pushViewController:CVC animated:YES];

}else {

LHQNotFullMarkCtrl *NVC = [CZStoryboard instantiateViewControllerWithIdentifier:@"LHQNotFullMarkCtrl"];

NVC.StateLabel3 = [ViewController loanStatusWithCode:14];;

[self.navigationController pushViewController:NVC animated:YES];

}

}

//组数

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 4;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return 1;

}

//每一行显示的内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellTableIdentifier = @"LHQInvestmentManagementCell";

LHQInvestmentManagementCell *cell = [tableView dequeueReusableCellWithIdentifier:

CellTableIdentifier forIndexPath:indexPath];

if (cell == nil)

{

cell = [[LHQInvestmentManagementCell alloc] init] ;

}

LHQInvestmentManagementModel *model = _dataArr[indexPath.section];

[cell customedWithModel:model];

return cell;

}

//每一行的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

//屏幕适配

if(SCREENH <= 480){

return 100;

}else if (SCREENH < 667){

return 100;

}else if (SCREENH == 667){

return 125;

}else {

return 150;

}

}

//借款状态对照码

+ (NSString *)loanStatusWithCode:(NSInteger)statusCode

{

NSString *loanStatusStr = nil;

switch (statusCode) {

case 0:{

loanStatusStr = @"审核中";

}

break;

case 1:{

loanStatusStr = @"提前借款";

}

break;

case 2:{

loanStatusStr = @"筹款中";

}

break;

case 3:{

loanStatusStr = @"待放款";

}

break;

case 4:{

loanStatusStr = @"还款中";

}

break;

case 5:{

loanStatusStr = @"已还款";

}

break;

case 10:{

loanStatusStr = @"审核中待验证";

}

break;

case 11:{

loanStatusStr = @"提前借款待验证";

}

break;

case 14:{

loanStatusStr = @"本金垫付还款中";

}

break;

case -10:{

loanStatusStr = @"未验证";

}

break;

case -100:{

loanStatusStr = @"资金托管提交中";

}

break;

case -5:{

loanStatusStr = @"撤销";

}

break;

case -4:{

loanStatusStr = @"流标";

}

break;

case -3:{

loanStatusStr = @"放款不通过";

}

break;

case -2:{

loanStatusStr = @"审核不通过";

}

break;

case -1:{

loanStatusStr = @"审核不通过";

}

break;

default:{

loanStatusStr = [NSString stringWithFormat:@"%zd",statusCode];

}

break;

}

return loanStatusStr;

}

@end



//

//  LHQInvestmentManagementCell.h

//  11 - 投资管理 - 李洪强

//

//  Created by vic fan on 16/4/15.

//  Copyright © 2016年 李洪强. All rights reserved.

//

#import <UIKit/UIKit.h>

@class LHQInvestmentManagementModel;

@interface LHQInvestmentManagementCell : UITableViewCell

-(void)customedWithModel:(LHQInvestmentManagementModel *)model;

@end


//

//  LHQInvestmentManagementCell.m

//  11 - 投资管理 - 李洪强

//

//  Created by vic fan on 16/4/15.

//  Copyright © 2016年 李洪强. All rights reserved.

//

#define SCREENW [UIScreen mainScreen].bounds.size.width

#define SCREENH [UIScreen mainScreen].bounds.size.height

#import "LHQInvestmentManagementCell.h"

//模型数据

#import "LHQInvestmentManagementModel.h"

#import "ViewController.h"

@interface LHQInvestmentManagementCell ()

//1 标识图片

@property (weak, nonatomic) IBOutlet UIImageView *IdentificationImage;

//主标题

@property (weak, nonatomic) IBOutlet UILabel *MainTitleLabel;

//2 标的状态

@property (weak, nonatomic) IBOutlet UILabel *TargetStateLabel;

//3 总额数字

@property (weak, nonatomic) IBOutlet UILabel *TotalLabel;

@property (weak, nonatomic) IBOutlet UILabel *TotalTextLabel;

//4 我的投资额下

@property (weak, nonatomic) IBOutlet UILabel *MyInvestmentAmountLabel;

//5 待收总额

@property (weak, nonatomic) IBOutlet UILabel *TotalAmountToBeCollected;

//最后的label

@property (weak, nonatomic) IBOutlet UILabel *lastLabel;

//图标

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ImageX;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ImageY;

//主标题

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MainTitleLabelX;

//标的状态

//标的状态宽

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *BidStatuesW;

//标的状态高

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *BidStatuesH;

//标的状态X

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *BidStatuesX;

//总额

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TotalLabelY;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TotalLabelX;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TotalNumY;

//我的投资额上

@property (weak, nonatomic) IBOutlet UILabel *MyInvestmentAmount;

//上

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MyInvestmentAmountX;

//下

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MyInvestmentAmountLabelX;

//待收总额

@property (weak, nonatomic) IBOutlet UILabel *TotalAmountLabel;

@end

@implementation LHQInvestmentManagementCell

//布局子控件- 屏幕适配

- (void)layoutSubviews{

if(SCREENH <= 480){

self.ImageX.constant = 15;

self.ImageY.constant  = 15;

self.MainTitleLabel.font = [UIFont systemFontOfSize:15];

self.MainTitleLabelX.constant = 5;

//标的状态

//标的状态label的宽

if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else{

self.BidStatuesW.constant = 65;

}

// self.BidStatuesW.constant = 60;

self.BidStatuesH.constant = 20;

self.TargetStateLabel.font = [UIFont systemFontOfSize:12];

//总额

self.TotalLabelX.constant = 15;

self.TotalLabelY.constant = 15;

self.TotalTextLabel.font = [UIFont systemFontOfSize:13];

self.TotalLabel.font = [UIFont systemFontOfSize:13];

//我的投资额

self.MyInvestmentAmount.font = [UIFont systemFontOfSize:13];

//待收总额

self.TotalAmountLabel.font = [UIFont systemFontOfSize:13];

//

self.TotalNumY.constant = 3;

self.MyInvestmentAmountLabel.font = [UIFont systemFontOfSize:13];

self.TotalAmountToBeCollected.font = [UIFont systemFontOfSize:13];

}else if (SCREENH < 667){

self.ImageX.constant = 15;

self.ImageY.constant  = 15;

self.MainTitleLabel.font = [UIFont systemFontOfSize:15];

self.MainTitleLabelX.constant = 5;

//标的状态

//标的状态label的宽

if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){

self.BidStatuesW.constant = 90;

self.BidStatuesX.constant = 5;

}else{

self.BidStatuesW.constant = 65;

}

// self.BidStatuesW.constant = 60;

self.BidStatuesH.constant = 20;

self.TargetStateLabel.font = [UIFont systemFontOfSize:12];

//总额

self.TotalLabelX.constant = 15;

self.TotalLabelY.constant = 15;

self.TotalTextLabel.font = [UIFont systemFontOfSize:13];

self.TotalLabel.font = [UIFont systemFontOfSize:13];

//我的投资额

self.MyInvestmentAmount.font = [UIFont systemFontOfSize:13];

//待收总额

self.TotalAmountLabel.font = [UIFont systemFontOfSize:13];

//

self.TotalNumY.constant = 3;

self.MyInvestmentAmountLabel.font = [UIFont systemFontOfSize:13];

self.TotalAmountToBeCollected.font = [UIFont systemFontOfSize:13];

}else if (SCREENH == 667){

//标的状态label的宽

if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){

self.BidStatuesW.constant = 110;

}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){

self.BidStatuesW.constant = 110;

}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){

self.BidStatuesW.constant = 110;

}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){

self.BidStatuesW.constant = 110;

}else{

self.BidStatuesW.constant = 80;

}

self.BidStatuesX.constant = 40;

self.TotalNumY.constant = 5;

self.MyInvestmentAmountX.constant = 80;

self.MyInvestmentAmountLabelX.constant = 35;

}else {

//标的状态label的宽

if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){

self.BidStatuesW.constant = 110;

}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){

self.BidStatuesW.constant = 110;

}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){

self.BidStatuesW.constant = 110;

}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){

self.BidStatuesW.constant = 110;

}else{

self.BidStatuesW.constant = 80;

}

self.BidStatuesX.constant = 70;

self.TotalNumY.constant = 5;

self.MyInvestmentAmountX.constant = 100;

self.MyInvestmentAmountLabelX.constant = 55;

self.TotalLabelY.constant = 30;

}

}

- (void)customedWithModel:(LHQInvestmentManagementModel *)model{

/**

@property(nonatomic)NSString *stutes;

@property(nonatomic)NSString *title;

@property(nonatomic)NSString *bidStutes;

@property(nonatomic)NSString *assets;

@property(nonatomic)NSString *invest;

@property(nonatomic)NSString *lastone;

*/

//1 标识图片

self.IdentificationImage.image = [UIImage imageNamed:model.stutes];

//2 大标题

self.MainTitleLabel.text = model.title;

//3 标的状态

self.TargetStateLabel.text = model.bidStutes;

//    if([self.TargetStateLabel.text isEqualToString:@"还款中"]){

//

//        self.TargetStateLabel.layer.masksToBounds = YES;

//        self.TargetStateLabel.layer.cornerRadius = 6;

//        self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];

//

//

//    }else if ([self.TargetStateLabel.text isEqualToString:@"已逾期"]){

//

//        self.TargetStateLabel.layer.masksToBounds = YES;

//        self.TargetStateLabel.layer.cornerRadius = 6;

//        self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];

//

//

//    }else if ([self.TargetStateLabel.text isEqualToString:@"已完成"]){

//        self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];

//

//

//        self.TargetStateLabel.layer.masksToBounds = YES;

//        self.TargetStateLabel.layer.cornerRadius = 6;

//        self.lastLabel.text = @"收益总额";

//    }else if ([self.TargetStateLabel.text isEqualToString:@"未满标"]){

//        self.lastLabel.text = @"已完成";

//        self.TargetStateLabel.layer.masksToBounds = YES;

//        self.TargetStateLabel.layer.cornerRadius = 6;

//

//    }

self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];

//

self.TargetStateLabel.layer.masksToBounds = YES;

self.TargetStateLabel.layer.cornerRadius = 6;

//4 总额

self.TotalLabel.text = model.assets;

//5 我的投资额

self.MyInvestmentAmountLabel.text = model.invest;

//6 待收总额

self.TotalAmountToBeCollected.text = model.lastone;

}

- (void)awakeFromNib {

// Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

@end



//

//  LHQInvestmentManagementModel.h

//  11 - 投资管理 - 李洪强

//

//  Created by vic fan on 16/4/15.

//  Copyright © 2016年 李洪强. All rights reserved.

//

#import <Foundation/Foundation.h>

@interface LHQInvestmentManagementModel : NSObject

//存放内容的数组

//1 图标

@property(nonatomic)NSString *stutes;

//2 大标题

@property(nonatomic)NSString *title;

//3 标的状态

@property(nonatomic)NSString *bidStutes;

//4 总额

@property(nonatomic)NSString *assets;

//5 我的投资额

@property(nonatomic)NSString *invest;

//6 待收金额

@property(nonatomic)NSString *lastone;

@end

//

//  LHQInvestmentManagementModel.m

//  11 - 投资管理 - 李洪强

//

//  Created by vic fan on 16/4/15.

//  Copyright © 2016年 李洪强. All rights reserved.

//

#import "LHQInvestmentManagementModel.h"

@implementation LHQInvestmentManagementModel

@end

给自定义cell赋值代码的更多相关文章

  1. 给自定义cell赋值

    搭建自定义cell-给自定义cell赋值的思路 1 主控制器 1.1导入头文件 #import "LHQInvestmentManagementCell.h" #import &q ...

  2. AJ学IOS(17)UI之纯代码自定义Cell实现新浪微博UI

    AJ分享,必须精品 先看效果图 编程思路 代码创建Cell的步骤 1> 创建自定义Cell,继承自UITableViewCell 2> 根据需求,确定控件,并定义属性 3> 用get ...

  3. 李洪强iOS开发之自定义cell的使用

    第一步: 创建自定义cell类,继承自UItableVIewcell 第二步: 在sb中布局自己需要的视图控件并且将此cell与我刚刚创建的cell类进行关联.并且连线  第三步: 创建modle类, ...

  4. iOS开发小技巧--纯代码自定义cell

    纯代码自定义cell 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样) 1.新建一个继承自UITableViewCell的子类 2.在initWithStyle:方 ...

  5. 通过代码自定义cell 新浪微博页面显示

    通过代码自定义cell(cell的高度不一致)(如果高度一致的cell 用xib实现) 1.新建一个集成自UItableVIewCell的类 2.重写initWithStle :方法 - (insta ...

  6. oc学习之路----通过代码自定义cell

    需求背景:由于tableView中每一个cell的数据与布局都不一样,故不能用xib实现功能,这是用代码写自定义cell就有必要了. 步骤 1.新建一个继承自UITableViewCell的类 2.重 ...

  7. UITableView自定义Cell中,纯代码编程动态获取高度

    在UITableView获取高度的代理方法中,经常需要根据实际的模型重新计算每个Cell的高度.直接的做法是在该代理方法中,直接根据模型来返回行高:另 [1]-(CGFloat)tableView:( ...

  8. iOS UI-微博案例(通过代码自定义Cell)

    一.Model BWWeiBo数据模型 #import <Foundation/Foundation.h> @interface BWWeiBo : NSObject @property ...

  9. 懒加载 字典转模型 自定义cell

    1 懒加载: 1>  什么是懒加载? 懒加载又称为延时加载,即在系统调用的时候加载,如果系统不调用则不会加载.所谓的懒加载其实就是重写其 get 方法. 2>  特点:在使用懒加载的时候要 ...

随机推荐

  1. RTP、RTCP及媒体流同步

    转自:http://blog.163.com/liu_nongfu/blog/static/19079414220139169225333/ 一.流媒体简介 流媒体是指在internet中使用流媒体技 ...

  2. linux文本模式下使用PPPOE拨号ADSL上网的方法

    转自:http://www.myzhenai.com.cn/post/945.html 转载请注明出处:http://www.myzhenai.com/thread-15431-1-1.html ht ...

  3. VS2010和matlab2010混合编程中char16_t重定义的问题

    原因是VS2010中的yvals.h添加了char16_t的定义,而Matlab的matrix.h也包含对char16_t的定义,所以同时包含这两个头文件的话,会导致重复定义char16_t的错误.只 ...

  4. 注解:【无连接表的】Hibernate单向1->N关联

    Person与Address关联:单向1->N,[无连接表的] (性能较低,不推荐使用!) Person.java package org.crazyit.app.domain; import ...

  5. 10个很棒的学习Android 开发的网站(转)

    看到江湖旅人 写的<10个很棒的学习iOS开发的网站 - 简书>,所以就忍不住写Android 啦,也希望对大家有帮助.我推荐的网站,都是我在学习Android 开发过程中发现的好网站,给 ...

  6. pythonyCool-moviepy

    你想要登上山顶去看美丽的风光,却在山腰发现了草莓. 今天给大家推荐一个很酷的python包moviepy.我在伯乐在线发现的看这个链接: http://python.jobbole.com/81185 ...

  7. Linux内核学习之道

    来自:http://blog.chinaunix.net/uid-26258259-id-3783679.html 内核文档 内核代码中包含有大量的文档,这些文档对于学习理解内核有着不可估量的价值,记 ...

  8. vs2015 MFC工程添加消息响应函数

    真不知道这PPT怎么描述的..最后窝找到了解决方法如上图.. 下次找MSDN解决问题好了..而且我们并不知道他所说的这个IDE到底是哪个厂商哪个版本的IDE这就很困惑 不过呢..它主要是让我们添加消息 ...

  9. js兼容方法:事件添加|事件绑定|事件监听 addEvent

    function addEvent(obj,sEvent,fn){ if(obj.attachEvent){ obj.attachEvent("on"+sEvent,fn); }e ...

  10. Thymeleaf模板引擎使用

    Thymeleaf模板引擎使用 什么是Thymeleaf Thymeleaf是一个Java库.它是一个XML / XHTML / HTML5模板引擎,能够在模板文件上应用一组转换,将程序产生的数据或者 ...