使用masonry进行Scrollview布局时,在scrollview中添加容器container,向container添加控件,在布局的最后,限制容器container的滑动高度[self.container makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.shuomingLbl.bottom);
}];
注意:放入容器container中的控件,控件布局的参照物只能选取container和container中的控件。
//
// MissionDetailViewController.m
//
// Created by yanglicheng-Leo on 15/7/9.
// Copyright (c) 2015年 Leo. All rights reserved.
//
#import "MissionDetailViewController.h"
#import "AppDelegate.h"
#import "UMSocial.h"
#import "PresentingAnimator.h"
#import "DismissingAnimator.h"
#import "CustomShareViewController.h"
#import "WriteComment7ViewController.h"
#import "MissionCommentTableViewCell.h"
#import "LogInViewController.h"
#import "MJExtension.h"
#import "UserState.h"
#import "TaskComment.h"
#import "YMMissionViewController.h"
#import "MyTaskModel.h"
#import "MyMissionViewController.h"
@interface MissionDetailViewController (){
NSMutableDictionary *shareDict;
Mission* mission;
NSMutableArray* commentArray;
NSInteger page_num;
NSInteger page_size;
CGFloat newHeight;
NSString* state;
}
@end
@implementation MissionDetailViewController
-(instancetype)initWithMission:(Mission*)missionDetail{
self=[super init];
shareDict = [[NSMutableDictionary alloc] init];
state=@"fdsfas";
mission=missionDetail;
page_size=20;
commentArray=[NSMutableArray array];
UIView* footBG=[UIView new];
footBG.backgroundColor=[UIColor clearColor];
self.commenttableView.tableFooterView=footBG;
return self;
}
#pragma mark - vc_life_cycle
-(void)viewDidLoad{
[super viewDidLoad];
_lblTitle.text=@"任务详情";
_lblTitle.textColor=[UIColor whiteColor];
[self addRightButton:@"[email protected]"];
_topView.backgroundColor=[Toolkit getColor:hex_red_color];
self.view.backgroundColor=[UIColor whiteColor];
//将self.view实例添加到self.view中
[self.view addSubview:self.scrollView];
[self.scrollView addSubview:self.container];
[self.container addSubview:self.missionDetailView];
[self.missionDetailView addSubview:self.missionImg];
[self.missionDetailView addSubview:self.missionNameLbl];
[self.missionDetailView addSubview:self.descLbl];
[self.missionDetailView addSubview:self.rewardLbl];
[self.missionDetailView addSubview:self.frequencyLbl];
[self.missionDetailView addSubview:self.divider_1];
[self.missionDetailView addSubview:self.baozhengjinLbl];
[self.missionDetailView addSubview:self.fajinLbl];
[self.missionDetailView addSubview:self.baozhengjinNumLbl];
[self.missionDetailView addSubview:self.fajinNumLbl];
[self.missionDetailView addSubview:self.divider_2];
[self.missionDetailView addSubview:self.restRequestNumLbl];
[self.missionDetailView addSubview:self.allNumLbl];
[self.missionDetailView addSubview:self.divider_3];
[self.container addSubview:self.segmentedControl];
[self.container addSubview:self.commenttableView];
[self.container addSubview:self.shuomingLbl];
[self.container addSubview:self.tiaoliLbl];
[self.view addSubview:self.requestMissionBtn];
//给view添加autolayout constraints
[self viewMakeMasConstraints];
[self getShareContent];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
[_app_ hiddenTabBar];
[self loadNewData];
[self loadNewCommentData];
[self requestMissionCommentCount];
}
-(void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
//!!!: delegate使用真实的protocol名称,按住cmd点击可以跳转protocol文件
#pragma mark - UITableViewDataSource UITableView数据源
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *TableIdentifier = @"COMMTableIdentifier";
MissionCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
TableIdentifier ];
if (cell == nil) {
cell = [[MissionCommentTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier: TableIdentifier ];
}
// cell.textLabel.text=[NSString stringWithFormat:@"评论%ld",indexPath.row];
TaskComment* taskComment=(TaskComment*)[commentArray objectAtIndex:indexPath.row];
[cell.cell_ImageView_1 sd_setImageWithURL:[NSURL URLWithString:taskComment.head_img] placeholderImage:[UIImage imageNamed:@"Def_headIcon"]];
cell.cell_Label_1.text=taskComment.user_name;
cell.cell_Label_2.text=taskComment.task_content;
cell.cell_Label_3.text=taskComment.add_time;
UILabel *label = cell.cell_Label_2;
NSString *text =taskComment.task_content;
CGRect cellFrame = [cell frame];
cellFrame.origin = CGPointMake(0, 0);
label.text = text;
CGRect rect = CGRectInset(cellFrame, 2, 2);
label.frame = rect;
[label sizeToFit];
if (label.frame.size.height > kHeightOfMissionCommentCell-29) {
cellFrame.size.height = kHeightOfMissionCommentCell + label.frame.size.height - kHeightOfMissionCommentCell+29+10;
}
else {
cellFrame.size.height = kHeightOfMissionCommentCell;
}
[cell setFrame:cellFrame];
return cell;
};
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return commentArray.count;
};
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView* header=[UIView new];
header.backgroundColor=[UIColor whiteColor];
UIView* divider_gray=[UIView new];
divider_gray.backgroundColor=[UIColor groupTableViewBackgroundColor];
[header addSubview:self.commentNumLbl];
[header addSubview:self.writeCommentImg];
[header addSubview:self.writeCommentLbl];
[header addSubview:divider_gray];
[self.commentNumLbl makeConstraints:^(MASConstraintMaker* make){
make.edges.equalTo(header).insets(UIEdgeInsetsMake(5, 15, 5, 100));
}];
[self.writeCommentLbl makeConstraints:^(MASConstraintMaker* make){
make.right.equalTo(header).offset(-10);
make.centerY.equalTo(header.centerY);
make.width.height.equalTo(70);
}];
[self.writeCommentImg makeConstraints:^(MASConstraintMaker* make){
make.right.equalTo(self.writeCommentLbl.left).offset(-5);
make.centerY.equalTo(header.centerY);
make.width.height.equalTo(20);
}];
[divider_gray makeConstraints:^(MASConstraintMaker* make){
make.bottom.equalTo(header);
make.left.equalTo(header);
make.right.equalTo(header);
make.height.equalTo(1);
}];
return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}
#pragma mark - UITableViewDelegate UITableView代理方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow]animated:YES];
}
#pragma mark - UIViewControllerTransitioningDelegate
- (id)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
return [PresentingAnimator new];
}
- (id)animationControllerForDismissedController:(UIViewController *)dismissed
{
return [DismissingAnimator new];
}
#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag==1000) {
if (buttonIndex==0) {
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:NO];
[[_app_ getTabBar] selectTableBarIndex:1];
}else{
MyMissionViewController* myMission=[[MyMissionViewController alloc ] init];
[self.navigationController pushViewController:myMission animated:YES];
}
}else if(alertView.tag==1001){
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:NO];
[[_app_ getTabBar] selectTableBarIndex:1];
}
}
#pragma mark - CustomDelegate 自定义代理方法
#pragma mark - 网络请求,数据请求
//提前做分享获取
-(void) getShareContent
{
NSMutableDictionary* dict=[NSMutableDictionary dictionary];
[dict setObject:@"Share.Index" forKey:@"service"];
// DLog(@"%ld",taskdetail.goods_id);
[dict setValue:mission.goods_id forKey:@"goods_id"];
[dict setObject:get_sp(kUserID)?get_sp(kUserID):@"" forKey:@"user_id"];
[dict setObject:get_sp(kSessionKey)?get_sp(kSessionKey):@"" forKey:@"sessionkey"];
[[Mall_APIManager sharedManager] request_Share_IndexWithParams:dict andBlock:^(id data,NSError* error){
if (data && [[data objectForKey:@"ret"] integerValue] == 200) {
id retDict = [[data objectForKey:@"data"] objectForKey:@"content"];
if (retDict) {
[shareDict setValue:[(NSString*)[retDict objectForKey:kShareTitle] length]>1?[retDict objectForKey:kShareTitle]:@"3658商城" forKey:kShareTitle];
[shareDict setValue:[(NSString*)[retDict objectForKey:kShareContent] length]>1?[retDict objectForKey:kShareContent]:@"3658商城" forKey:kShareContent];
[shareDict setValue:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[retDict objectForKey:kShareImageURL]]]]] forKey:kShareImageURL];
[shareDict setValue:[retDict objectForKey:kShareURL] forKey:kShareURL];
};
}
}];
}
-(void)loadNewCommentData{
page_num=1;
NSMutableDictionary* dict=[NSMutableDictionary dictionary];
[dict setObject:@"TaskComment.Index" forKey:@"service"];
[dict setObject:mission.goods_id forKey:@"goods_id"];
[dict setObject:[NSString stringWithFormat:@"%ld",page_num] forKey:@"page_num"];
[dict setObject:[NSString stringWithFormat:@"%ld",page_size] forKey:@"page_size"];
[[Mall_APIManager sharedManager] request_TaskComment_IndexWithParams:dict andBlock:^(id data,NSError* error){
NSNumber* ret=[data objectForKey:@"ret"];
if ([ret isEqualToNumber:kRequestSuccess]) {
commentArray=[TaskComment objectArrayWithKeyValuesArray:[[data objectForKey:@"data"] objectForKey:@"content"]];
[self.commenttableView reloadData];
}else if ([ret isEqualToNumber:kRequestNotHaveData]){
}
[self.commenttableView.header endRefreshing];
}];
}
-(void)loadMoreCommentData{
page_num++;
NSMutableDictionary* dict=[NSMutableDictionary dictionary];
[dict setObject:@"TaskComment.Index" forKey:@"service"];
[dict setObject:mission.goods_id forKey:@"goods_id"];
[dict setObject:[NSString stringWithFormat:@"%ld",page_num] forKey:@"page_num"];
[dict setObject:[NSString stringWithFormat:@"%ld",page_size] forKey:@"page_size"];
[[Mall_APIManager sharedManager] request_TaskComment_AddWithParams:dict andBlock:^(id data,NSError* error){
NSNumber* ret=[data objectForKey:@"ret"];
if ([ret isEqualToNumber:kRequestSuccess]) {
[commentArray addObjectsFromArray:[TaskComment objectArrayWithKeyValuesArray:[[data objectForKey:@"data"] objectForKey:@"content"]]];
[self.commenttableView reloadData];
}
[self.commenttableView.footer endRefreshing];
}];
}
-(void)loadNewData{
[[Mall_APIManager sharedManager] request_TaskDetailWithParams:[mission toMissionDetailParam] andBlock:^(id data,NSError* error){
NSNumber* ret=[data objectForKey:@"ret"];
if([ret isEqualToNumber:kRequestSuccess]){
mission=[Mission objectWithKeyValues:[[data objectForKey:@"data" ] objectForKey:@"content"]];
[self setModelInfoToVC:mission];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.scrollView.header endRefreshing];
[SVProgressHUD dismiss];
});
}else if([ret isEqualToNumber:kRequestUserNoLogin]){
}else if([ret isEqualToNumber:kRequestNotHaveData]){
}else if([ret isEqualToNumber:kRequestError]){
[self.scrollView.header endRefreshing];
[SVProgressHUD dismiss];
[SVProgressHUD showErrorWithStatus:[data objectForKey:@"msg"] maskType:SVProgressHUDMaskTypeBlack];
[self.navigationController popViewControllerAnimated:YES];
}
if(error){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(HUDShowTimeInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
}
}];
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
}
-(void)requestMission{
[[Mall_APIManager sharedManager] request_ReceiveTaskWithParams:[mission toReceiveTaskParam] andBlock:^(id data,NSError* error){
NSNumber* ret=[data objectForKey:@"ret"];
if ([ret isEqualToNumber:kRequestSuccess]) {
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"领取成功" message:[[[data objectForKey:@"data"] objectForKey:@"content"] objectForKey:@"msg"] delegate:self cancelButtonTitle:@"继续领取" otherButtonTitles:@"去做任务", nil];
alert.tag=1000;
[alert show];
}else{
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"领取失败" message:[data objectForKey:@"msg"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
alert.tag=1001;
[alert show];
}
}];
}
-(void)requestMissionCommentCount{
NSMutableDictionary* dict=[NSMutableDictionary dictionary];
[dict setObject:@"TaskComment.CountNum" forKey:@"service"];
[dict setObject:mission.goods_id forKey:@"goods_id"];
[[Mall_APIManager sharedManager] request_TaskComment_CountNumWithParams:dict andBlock:^(id data,NSError* error){
NSNumber* ret=[data objectForKey:@"ret"];
if([ret isEqualToNumber:kRequestSuccess]){
self.commentNumLbl.text=[NSString stringWithFormat:@"%@条评论",[[data objectForKey:@"data"] objectForKey:@"content"]];
}else if([ret isEqualToNumber:kRequestUserNoLogin]){
}else if([ret isEqualToNumber:kRequestNotHaveData]){
}
}];
}
#pragma mark - event response button、gestureRecognizer的响应事件
-(void)clickRightButton:(UIButton *)sender{
MyTaskDetail* detail=[MyTaskDetail new];
detail.task_type=MissionInvitation;
YMMissionViewController * shareVC=[[YMMissionViewController alloc] initWithMission:detail];
shareVC.modalPresentationStyle = UIModalPresentationCustom;
shareVC.shareDict = shareDict;
shareVC.NotInviteIsShare=TRUE;
// shareVC.productAD = productAD;
// shareVC.delegate=self;
[self.navigationController presentViewController:shareVC animated:YES completion:^{
}];
}
-(void)requestMission:(id*)sender{
// CustomShareViewController* shareVC=[CustomShareViewController new];
// shareVC.transitioningDelegate=self;
// shareVC.modalPresentationStyle=UIModalPresentationCustom;
// [self.navigationController presentViewController:shareVC animated:YES completion:NULL];
if ([[UserState sharedManager] isLogin]) {
[self requestMission];
}else{
[SVProgressHUD showErrorWithStatus:@"亲,请先登陆哦!" maskType:SVProgressHUDMaskTypeBlack];
LogInViewController* loginVC=[[LogInViewController alloc] init];
[self.navigationController pushViewController:loginVC animated:YES];
}
}
- (void)segmentedControlChangedValue:(UISegmentedControl *)segmentedControl {
NSLog(@"Selected index %ld (via UIControlEventValueChanged)", (long)segmentedControl.selectedSegmentIndex);
switch (segmentedControl.selectedSegmentIndex) {
case 0:{
self.shuomingLbl.hidden=NO;
self.commenttableView.hidden=YES;
self.tiaoliLbl.hidden=YES;
break;
}
case 1:{
self.shuomingLbl.hidden=YES;
self.commenttableView.hidden=NO;
self.tiaoliLbl.hidden=YES;
break;
}
case 2:{
self.shuomingLbl.hidden=YES;
self.commenttableView.hidden=YES;
self.tiaoliLbl.hidden=NO;
break;
}
default:
break;
}
}
-(void)commitComment:(id)sender{
if (![[UserState sharedManager] isLogin]) {
kTipAlert(@"请先登录之后,再来进行任务评论");
return;
}
WriteComment7ViewController* commentVC=[[WriteComment7ViewController alloc] initWithMission:mission];
[self.navigationController pushViewController:commentVC animated:YES];
}
#pragma mark - private methods 自定义私有方法
#pragma mark UILabel 自动高度计算
- (CGFloat) labelAutoHeight:(UILabel *) contentLabel text:(NSString *) text {
UIFont *font = [UIFont systemFontOfSize:12];
contentLabel.font = font;
[contentLabel setNumberOfLines:0];
contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
// contentLabel.backgroundColor = [UIColor greenColor];
contentLabel.tag = 102;
CGSize size = CGSizeMake(SCREEN_WIDTH-90,2000);
CGSize labelsize = [text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
// [contentLabel setFrame:CGRectMake(20, 30, 320, labelsize.height)];
return labelsize.height;
}
/**
* 将model的内容设置在界面中
*
* @param missionInfo model
*/
-(void)setModelInfoToVC:(Mission*)missionInfo{
[self.missionImg sd_setImageWithURL:[NSURL URLWithString:[missionInfo goods_img]] placeholderImage:[UIImage imageNamed:@"mission"]];
self.missionNameLbl.text=missionInfo.goods_name;
NSString* shuoming=missionInfo.task_desc;
NSString* tiaoli=missionInfo.user_regulations;
for (int i=0; i<10; i++) {
shuoming =[shuoming stringByAppendingString:@"\n"];
tiaoli=[tiaoli stringByAppendingString:@"\n"];
}
NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:shuoming];
NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setLineSpacing:10];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [shuoming length])];
[self.shuomingLbl setAttributedText:attributedString1];
// [self.shuomingLbl sizeToFit];
// self.shuomingLbl.text=missionInfo.task_desc;
// [self.shuomingLbl alignTop];
NSMutableAttributedString * attributedString2 = [[NSMutableAttributedString alloc] initWithString:tiaoli];
NSMutableParagraphStyle * paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle2 setLineSpacing:10];
[attributedString2 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle2 range:NSMakeRange(0, [tiaoli length])];
[self.tiaoliLbl setAttributedText:attributedString2];
// self.tiaoliLbl.text=missionInfo.user_regulations;
// [self.tiaoliLbl alignTop];
self.baozhengjinNumLbl.text=missionInfo.margin_price;
self.fajinNumLbl.text=missionInfo.failure_money;
self.allNumLbl.text=[NSString stringWithFormat:@"累计领取上限%@次",[missionInfo.limit_receive_count isEqualToString:@"0"]?@"为无限":missionInfo.limit_receive_count];
self.restRequestNumLbl.text=[NSString stringWithFormat:@"剩余领取数量%ld次",missionInfo.ream_share_bonus_number];
// NSString* red=[Toolkit toDivideNumberHJB:[NSString stringWithFormat:@"%@",missionInfo.red_campbell]];
NSString* str=[NSString stringWithFormat:@"%ld 红金宝奖励",missionInfo.red_campbell];
NSMutableAttributedString* attributed=[[NSMutableAttributedString alloc] initWithString:str];
[attributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, str.length-6)];
[attributed addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue" size:25.0] range:NSMakeRange(0, str.length-6)];
[attributed addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue" size:15.0] range:NSMakeRange(str.length-5, 5)];
self.rewardLbl.attributedText=attributed;
if ([missionInfo.task_type_name isEqualToString:@"分享任务"]) {
self.descLbl.text=@"通过分享信息获得任务奖励";
}else if([missionInfo.task_type_name isEqualToString:@"邀请任务"]){
self.descLbl.text=@"通过邀请朋友获得任务奖励";
}else if([missionInfo.task_type_name isEqualToString:@"看商品任务"]){
self.descLbl.text=@"通过观看商品获得任务奖励";
}else if([missionInfo.task_type_name isEqualToString:@"看图片任务"]){
self.descLbl.text=@"通过观看图片获得任务奖励";
}
self.frequencyLbl.text=[NSString stringWithFormat:@"共%@次 每天%ld次",missionInfo.gonghuo_goods_number,missionInfo.day_num];
}
#pragma mark - getters and setters 定义view实例的存取方法,view使用getter方法进行初始化
-(UIScrollView *)scrollView{
if (_scrollView==nil) {
_scrollView=[UIScrollView new];
_scrollView.showsVerticalScrollIndicator=NO;
_scrollView.header=[MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
}
return _scrollView;
}
-(UIView *)container{
if (_container==nil) {
_container=[UIView new];
}
return _container ;
}
#pragma mark 内容描述区域
-(UIView *)missionDetailView{
if (_missionDetailView==nil) {
_missionDetailView=[UIView new];
_missionDetailView.backgroundColor=[UIColor whiteColor];
}
return _missionDetailView;
}
-(UIImageView *)missionImg{
if (_missionImg==nil) {
_missionImg=[UIImageView new];
_missionImg.image=[UIImage imageNamed:@"[email protected]"];
[_missionImg sizeToFit ];
}
return _missionImg;
}
-(UILabel *)missionNameLbl{
if (_missionNameLbl==nil) {
_missionNameLbl=[UILabel new];
_missionNameLbl.text=@"看图片任务";
_missionNameLbl.font=[UIFont fontWithName:@"Arial-BoldMT" size:18.0];
_missionNameLbl.textColor=[Toolkit getColor:hex_282828];
}
return _missionNameLbl;
}
-(UILabel *)descLbl{
if (_descLbl==nil) {
_descLbl=[UILabel new];
_descLbl.text=@"";
_descLbl.textColor=[Toolkit getColor:hex_aaaaaa];
_descLbl.font=[UIFont fontWithName:@"Courier" size:12.0];
}
return _descLbl;
}
-(UILabel *)rewardLbl{
if (_rewardLbl==nil) {
_rewardLbl=[UILabel new];
}
return _rewardLbl;
}
-(UILabel *)frequencyLbl{
if (_frequencyLbl==nil) {
_frequencyLbl=[UILabel new];
_frequencyLbl.text=@"共0次 每天0次";
_frequencyLbl.textColor=[Toolkit getColor:hex_606060];
_frequencyLbl.font=[UIFont systemFontOfSize:15.0];
}
return _frequencyLbl;
}
-(UIView *)divider_1{
if (_divider_1==nil) {
_divider_1=[UIView new];
_divider_1.backgroundColor=[UIColor groupTableViewBackgroundColor];
}
return _divider_1;
}
-(UILabel *)baozhengjinLbl{
if (_baozhengjinLbl==nil) {
_baozhengjinLbl=[UILabel new];
_baozhengjinLbl.text=@"保证金";
_baozhengjinLbl.textAlignment=NSTextAlignmentCenter;
_baozhengjinLbl.textColor=[Toolkit getColor:@"808080"];
_baozhengjinLbl.font=[UIFont systemFontOfSize:14.0];
}
return _baozhengjinLbl;
}
-(UILabel *)fajinLbl{
if (_fajinLbl==nil) {
_fajinLbl=[UILabel new];
_fajinLbl.text=@"失败罚金";
_fajinLbl.textAlignment=NSTextAlignmentCenter;
_fajinLbl.textColor=[Toolkit getColor:@"808080"];
_fajinLbl.font=[UIFont systemFontOfSize:14.0];
}
return _fajinLbl;
}
-(UILabel *)baozhengjinNumLbl{
if (_baozhengjinNumLbl==nil) {
_baozhengjinNumLbl=[UILabel new];
_baozhengjinNumLbl.text=@"¥0.00";
_baozhengjinNumLbl.textAlignment=NSTextAlignmentCenter;
_baozhengjinNumLbl.textColor=[Toolkit getColor:@"282828"];
_baozhengjinNumLbl.font=[UIFont systemFontOfSize:14.0];
}
return _baozhengjinNumLbl;
}
-(UILabel *)fajinNumLbl{
if (_fajinNumLbl==nil) {
_fajinNumLbl=[UILabel new];
_fajinNumLbl.text=@"0红金宝";
_fajinNumLbl.textAlignment=NSTextAlignmentCenter;
_fajinNumLbl.textColor=[Toolkit getColor:@"282828"];
_fajinNumLbl.font=[UIFont systemFontOfSize:14.0];
}
return _fajinNumLbl;
}
-(UIView *)divider_2{
if (_divider_2==nil) {
_divider_2=[UIView new];
_divider_2.backgroundColor=[Toolkit getColor:hex_f3f3f3];
}
return _divider_2;
}
-(UILabel *)restRequestNumLbl{
if (_restRequestNumLbl==nil) {
_restRequestNumLbl=[UILabel new];
_restRequestNumLbl.text=@"剩余领取数量0次";
_restRequestNumLbl.textAlignment=NSTextAlignmentCenter;
_restRequestNumLbl.textColor=[Toolkit getColor:@"808080"];
_restRequestNumLbl.font=[UIFont systemFontOfSize:14.0];
}
return _restRequestNumLbl;
}
-(UILabel *)allNumLbl{
if (_allNumLbl==nil) {
_allNumLbl=[UILabel new];
_allNumLbl.text=@"累计领取上限0次";
_allNumLbl.textAlignment=NSTextAlignmentCenter;
_allNumLbl.textColor=[Toolkit getColor:@"808080"];
_allNumLbl.font=[UIFont systemFontOfSize:14.0];
}
return _allNumLbl;
}
-(UIView *)divider_3{
if (_divider_3==nil) {
_divider_3=[UIView new];
_divider_3.backgroundColor=[Toolkit getColor:hex_f3f3f3];
}
return _divider_3;
}
#pragma mark segmentcontrol
-(UISegmentedControl *)segmentedControl{
if (_segmentedControl==nil) {
_segmentedControl=[[UISegmentedControl alloc] initWithItems:@[@"任务说明",@"任务评论",@"用户条例"]];
[_segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
_segmentedControl.tintColor=[Toolkit getColor:hex_aaaaaa];
[_segmentedControl setSelectedSegmentIndex:0];
}
return _segmentedControl;
}
#pragma mark 任务说明、任务评论、用户条例内容区域
-(UITableView *)commenttableView{
if (_commenttableView==nil) {
_commenttableView=[UITableView new];
_commenttableView.delegate=self;
_commenttableView.dataSource=self;
_commenttableView.hidden=YES;
_commenttableView.header=[MJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewCommentData)];
_commenttableView.footer=[MJRefreshBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreCommentData)];
}
return _commenttableView;
}
-(UILabel *)commentNumLbl{
if (_commentNumLbl==nil) {
_commentNumLbl=[UILabel new];
_commentNumLbl.text=@"0条评论";
_commentNumLbl.font=[UIFont systemFontOfSize:14.0];
_commentNumLbl.textColor=[Toolkit getColor:hex_aaaaaa];
}
return _commentNumLbl;
}
-(UIImageView *)writeCommentImg{
if (_writeCommentImg==nil) {
_writeCommentImg=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"write_comment"]];
_writeCommentImg.userInteractionEnabled=YES;
UITapGestureRecognizer* tap=[UITapGestureRecognizer new];
[tap addTarget:self action:@selector(commitComment:)];
[_writeCommentImg addGestureRecognizer:tap];
}
return _writeCommentImg;
}
-(UILabel *)writeCommentLbl{
if (_writeCommentLbl==nil) {
_writeCommentLbl=[UILabel new];
_writeCommentLbl.text=@"撰写评论";
_writeCommentLbl.font=[UIFont systemFontOfSize:16.0];
_writeCommentLbl.userInteractionEnabled=YES;
UITapGestureRecognizer* tap=[UITapGestureRecognizer new];
[tap addTarget:self action:@selector(commitComment:)];
[_writeCommentLbl addGestureRecognizer:tap];
}
return _writeCommentLbl;
}
-(UILabel *)tiaoliLbl{
if (_tiaoliLbl==nil) {
_tiaoliLbl=[UILabel new];
_tiaoliLbl.numberOfLines=25;
_tiaoliLbl.font=[UIFont systemFontOfSize:16.0];
_tiaoliLbl.textColor=[UIColor darkGrayColor];
_tiaoliLbl.hidden=YES;
_tiaoliLbl.lineBreakMode=NSLineBreakByCharWrapping;
}
return _tiaoliLbl;
}
-(UILabel *)shuomingLbl{
if (_shuomingLbl==nil) {
_shuomingLbl=[UILabel new];
_shuomingLbl.numberOfLines=25;
_shuomingLbl.font=[UIFont systemFontOfSize:16.0];
_shuomingLbl.hidden=NO;
_shuomingLbl.textColor=[UIColor darkGrayColor];
_shuomingLbl.lineBreakMode=NSLineBreakByCharWrapping;
}
return _shuomingLbl;
}
-(UIButton *)requestMissionBtn{
if (_requestMissionBtn==nil) {
_requestMissionBtn=[UIButton new];
_requestMissionBtn.backgroundColor=[Toolkit getColor:hex_red_color];
[_requestMissionBtn setTitle:@"立即领取" forState:UIControlStateNormal];
_requestMissionBtn.tintColor=[UIColor whiteColor];
[_requestMissionBtn addTarget:self action:@selector(requestMission:) forControlEvents:UIControlEventTouchUpInside];
}
return _requestMissionBtn;
}
#pragma mark - AutoLayout代码布局
/**
* 给vc中的view添加autolayout constraints
*/
-(void)viewMakeMasConstraints{
int detail_height=300;
int navi_height=64;
int btn_height=44;
int seg_height=30;
int table_height=SCREEN_HEIGHT-navi_height-btn_height-seg_height;
[self.scrollView makeConstraints:^(MASConstraintMaker* make){
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(navi_height, 0, btn_height, 0));
}];
[self.container makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[self.missionDetailView makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.container.top);
make.left.equalTo(self.container);
make.right.equalTo(self.container);
make.height.equalTo(detail_height);
}];
[self.missionImg makeConstraints:^(MASConstraintMaker* make){
make.top.and.left.equalTo(self.missionDetailView).offset(10);
make.width.and.height.equalTo(268/2);
}];
[self.missionNameLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.missionImg.top).offset(10);
make.left.equalTo(self.missionImg.right).offset(16);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(20);
}];
[self.descLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.missionNameLbl.bottom).offset(10);
make.left.equalTo(self.missionImg.right).offset(16);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(20);
}];
[self.rewardLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.descLbl.bottom).offset(15);
make.left.equalTo(self.missionImg.right).offset(16);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(20);
}];
[self.frequencyLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.rewardLbl.bottom).offset(20);
make.left.equalTo(self.missionImg.right).offset(16);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(20);
}];
[self.divider_1 makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.missionImg.bottom).offset(13);
make.left.equalTo(self.missionDetailView);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(1);
}];
[self.baozhengjinLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.divider_1).offset(27.0/2);
make.left.equalTo(0);
make.right.equalTo(self.missionDetailView.centerX);
make.height.equalTo(14);
}];
[self.fajinLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.divider_1).offset(27.0/2);
make.left.equalTo(self.missionDetailView.centerX);
make.right.equalTo(0);
make.height.equalTo(14);
}];
[self.baozhengjinNumLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.baozhengjinLbl.bottom).offset(25.0/2);
make.left.equalTo(self.missionDetailView);
make.right.equalTo(self.missionDetailView.centerX);
make.height.equalTo(14);
}];
[self.fajinNumLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.fajinLbl.bottom).offset(25.0/2);
make.left.equalTo(self.missionDetailView.centerX);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(14);
}];
[self.divider_2 makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.divider_1).offset(62);
make.left.equalTo(self.missionDetailView);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(1);
}];
[self.restRequestNumLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.divider_2).offset(17);
make.left.equalTo(self.missionDetailView);
make.right.equalTo(self.missionDetailView.centerX);
make.height.equalTo(14);
}];
[self.allNumLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.divider_2).offset(17);
make.left.equalTo(self.missionDetailView.centerX);
make.right.equalTo(self.missionDetailView.right);
make.height.equalTo(14);
}];
[self.divider_3 makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.divider_2).offset(44);
make.left.equalTo(self.missionDetailView);
make.right.equalTo(self.missionDetailView);
make.height.equalTo(1);
}];
[self.segmentedControl makeConstraints:^(MASConstraintMaker* make){
// make.top.equalTo(self.missionDetailView.bottom);
make.top.equalTo(self.divider_3).offset(11);
make.right.equalTo(self.container).offset(-15);
make.left.equalTo(self.container).offset(15);
make.height.equalTo(seg_height);
// make.top.greaterThanOrEqualTo(self.view).offset(64);
}];
[self.commenttableView makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.segmentedControl.bottom).offset(5);
make.left.equalTo(self.container);
make.right.equalTo(self.container);
// make.height.equalTo(table_height) ;
make.bottom.equalTo(self.requestMissionBtn.top);
}];
[self.shuomingLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.segmentedControl.bottom);
make.left.equalTo(self.container).offset(10);
make.right.equalTo(self.container).offset(-5);
make.height.equalTo(table_height) ;
// make.bottom.equalTo(self.requestMissionBtn.top);
}];
[self.tiaoliLbl makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.segmentedControl.bottom);
make.left.equalTo(self.container).offset(10);
make.right.equalTo(self.container).offset(-5);
make.height.equalTo(table_height) ;
// make.bottom.equalTo(self.requestMissionBtn.top);
}];
[self.container makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.shuomingLbl.bottom);
}];
[self.requestMissionBtn makeConstraints:^(MASConstraintMaker* make){
make.left.right.bottom.equalTo(self.view);
make.height.equalTo(btn_height);
}];
}
@end