123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- //
- // PdDetailBottomView.m
- // FirstLink
- //
- // Created by jack on 15/7/17.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "PdDetailBottomView.h"
- #define kContentViewTagBase 120
- @implementation PdDetailBottomView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self initialize];
- }
- return self;
- }
- - (void)initialize
- {
- self.state = kPindanStateNormal;
- self.backgroundColor = [UIColor whiteColor];
-
- UIView *content0 = [[UIView alloc]init];
- UIView *content1 = [[UIView alloc]init];
- UIView *content2 = [[UIView alloc]init];
- UIView *topLine = [[UIView alloc]init];
- UIView *leftLine = [[UIView alloc]init];
- UIView *rightLine = [[UIView alloc]init];
-
- content0.backgroundColor = [UIColor clearColor];
- content1.backgroundColor = [UIColor clearColor];
- content2.backgroundColor = [UIColor clearColor];
- content0.tag = kContentViewTagBase + 0;
- content1.tag = kContentViewTagBase + 1;
- content2.tag = kContentViewTagBase + 2;
-
- topLine.backgroundColor = UIColorFromRGB(0xcccccc);
- leftLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
- rightLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
-
- [self addSubview:content0];
- [self addSubview:content1];
- [self addSubview:content2];
- [self addSubview:topLine];
- [self addSubview:leftLine];
- [self addSubview:rightLine];
- [self addSubview:self.commitBtn];
-
- [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.equalTo(self);
- make.height.equalTo(@0.5);
- }];
-
- [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(10);
- make.bottom.equalTo(self).offset(- 10);
- make.left.equalTo(self).offset(55);
- make.width.equalTo(@0.5);
- }];
-
- [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.width.equalTo(leftLine);
- make.left.equalTo(leftLine.mas_right).offset(55);
- }];
-
- [content0 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(topLine.mas_bottom);
- make.right.equalTo(leftLine.mas_left);
- make.left.bottom.equalTo(self);
- }];
-
- [content1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(leftLine.mas_right);
- make.right.equalTo(rightLine.mas_left);
- make.bottom.equalTo(self);
- make.top.equalTo(topLine.mas_bottom);
- }];
-
- [content2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(rightLine.mas_right);
- make.bottom.equalTo(self);
- make.top.equalTo(topLine.mas_bottom);
- make.width.equalTo(content1);
- }];
-
- [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.right.equalTo(self).offset(- 15);
- // make.centerY.equalTo(self);
- // make.height.equalTo(@35);
- // make.width.equalTo(@125);
- make.top.right.bottom.equalTo(self);
- make.width.equalTo(@140);
- }];
-
- [self pvt_initialPartView:content0 withTitle:@"评论" normalImg:@"detail_comment_n" hlImg:@"detail_comment_h" btnTag:kBottomCommentBtnTag];
- [self pvt_initialPartView:content1 withTitle:@"分享" normalImg:@"detail_share_n" hlImg:@"detail_share_h" btnTag:kBottomShareBtnTag];
- [self pvt_initialPartView:content2 withTitle:@"客服" normalImg:@"detail_service_n" hlImg:@"detail_service_h" btnTag:kBottomServiceBtnTag];
- }
- - (void)pvt_initialPartView:(UIView *)content withTitle:(NSString *)title normalImg:(NSString *)imageName hlImg:(NSString *)highlightImg btnTag:(kBottomBtnTag)btnTag
- {
- UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
-
- UILabel *label = ({
- UILabel *label = [[UILabel alloc]init];
- label.backgroundColor = [UIColor clearColor];
- label.font = [UIFont systemFontOfSize:12];
- label.textColor = UIColorFromRGB(0x999999);
- label.textAlignment = NSTextAlignmentCenter;
- label.text = title;
- label;
- });
-
- UIButton *button = ({
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.tag = btnTag;
- [btn addTarget:self action:@selector(commitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn;
- }); // 用于触发点击事件
-
- [content addSubview:imageView];
- [content addSubview:label];
- [content addSubview:button];
-
- [button mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
-
- [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(content).offset(7);
- make.centerX.equalTo(content);
- }];
-
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(imageView);
- // make.top.equalTo(imageView.mas_bottom).offset(3);
- make.bottom.equalTo(content).offset(- 4);
- }];
- }
- - (void)commitBtnClick:(UIButton *)sender
- {
- if ([self.delegate respondsToSelector:@selector(detailMenuBtnClickWithIndex:)]) {
- [self.delegate detailMenuBtnClickWithIndex:sender.tag];
- }
- }
- - (void)setState:(kPindanState)state
- {
- _state = state;
-
- NSString *title = nil;
- UIColor *titleColor = nil;
-
- switch (state) {
- case kPindanStateWaitBegin:{
- title = @"即将开启";
- titleColor = UIColorFromRGB(0x333333);
- }
- break;
- case kPindanStateNormal:{
- title = @"立即拼单";
- titleColor = UIColorFromRGB(0xff6362);
- }
- break;
- case kPindanStateRemind:{
- title = @"我想买";
- titleColor = UIColorFromRGB(0xfdc03c);
- }
- break;
- case kPindanStateCancelRemind:{
- title = @"已开启提醒";
- titleColor = UIColorFromRGB(0xcccccc);
- }
- break;
- case kPindanStateOnlyNew:{
- title = @"新用户专享";
- titleColor = UIColorFromRGB(0xcccccc);
- }
- break;
- case kPindanStateOnlyVIP:{
- title = @"会员专享";
- titleColor = UIColorFromRGB(0xcccccc);
- }
- break;
- case kPindanStateSaleDone:{
- title = @"我想买";
- titleColor = UIColorFromRGB(0xcccccc);
- }
- break;
- default:
- break;
- }
- [self.commitBtn setTitle:title forState:UIControlStateNormal];
- [self.commitBtn setBackgroundColor:titleColor];
- }
- - (UIButton *)commitBtn
- {
- if (_commitBtn == nil) {
- _commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_commitBtn setTitle:@"立即拼单" forState:UIControlStateNormal];
- [_commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [_commitBtn setBackgroundColor:UIColorFromRGB(0xff6362)];
- [_commitBtn addTarget:self action:@selector(commitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- _commitBtn.titleLabel.font = [UIFont systemFontOfSize:16];
- // _commitBtn.layer.cornerRadius = 5;
- _commitBtn.tag = kBottomConfirmBtnTag;
- }
- return _commitBtn;
- }
- @end
|