123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // DRSearchCoupleBottomView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/11/27.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRSearchCoupleBottomView.h"
- #import "DRGoodDetailModel.h"
- #define buttonWidth (SCREEN_WIDTH-20)
- @interface DRSearchCoupleBottomView ()
- @property (nonatomic, strong) UIButton *searchBtn;
- @property (nonatomic, strong) UIButton *payBtn;
- @property (nonatomic, strong) UIButton *discountBtn;
- @end
- @implementation DRSearchCoupleBottomView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor homeRedColor];
- [self initUI];
- }
- return self;
- }
- - (void)initUI {
- [self addSubview:self.searchBtn];
- [self addSubview:self.payBtn];
- [self addSubview:self.discountBtn];
- }
- - (void)showSearch {
- self.searchBtn.hidden = NO;
- self.payBtn.hidden = YES;
- self.discountBtn.hidden = YES;
- }
- - (void)showPay {
- self.searchBtn.hidden = YES;
- self.payBtn.hidden = NO;
- }
- - (void)searchCouple {
- if (self.delegate && [self.delegate respondsToSelector:@selector(bottomViewSearchClick)]) {
- [self.delegate bottomViewSearchClick];
- }
- }
- - (void)payAction {
- if ([self.delegate respondsToSelector:@selector(bottomViewPayClick)]) {
- [self.delegate bottomViewPayClick];
- }
- }
- - (UIButton *)searchBtn {
- if (!_searchBtn) {
- _searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, buttonWidth, 40)];
- [_searchBtn setTitle:@"搜索优惠券" forState:UIControlStateNormal];
- [_searchBtn setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
- [_searchBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:7];
- _searchBtn.backgroundColor=[UIColor YHColorWithHex:0xFA2C36];
- _searchBtn.layer.cornerRadius=20;
- _searchBtn.layer.masksToBounds=YES;
- _searchBtn.titleLabel.font = [UIFont systemFontOfSize:15];
- [_searchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [_searchBtn addTarget:self action:@selector(searchCouple) forControlEvents:UIControlEventTouchUpInside];
- }
- return _searchBtn;
- }
- -(UIButton *)discountBtn
- {
- if (!_discountBtn) {
- _discountBtn = [[UIButton alloc] initWithFrame:CGRectMake(10+buttonWidth/3, 5, buttonWidth/3, self.height-10)];
- _discountBtn.hidden=YES;
- [_discountBtn setTitle:@"券" forState:UIControlStateNormal];
- [_discountBtn setImage:[UIImage imageNamed:@"quan-2"] forState:UIControlStateNormal];
- _discountBtn.titleLabel.font = [UIFont systemFontOfSize:15];
- _discountBtn.backgroundColor = [UIColor YHColorWithHex:0xFA2C36];
- [_discountBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:7];
- [_discountBtn addTarget:self action:@selector(payAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _discountBtn;
- }
- - (UIButton *)payBtn {
- if (!_payBtn) {
- _payBtn = [[UIButton alloc] initWithFrame:CGRectMake(buttonWidth/3+10.5, 5, buttonWidth/3, self.height-10)];
- [_payBtn setTitle:@"立即购买" forState:UIControlStateNormal];
- _payBtn.backgroundColor = [UIColor YHColorWithHex:0xFA2C36];
- _payBtn.titleLabel.font = [UIFont systemFontOfSize:15];
- [_payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [_payBtn addTarget:self action:@selector(payAction) forControlEvents:UIControlEventTouchUpInside];
- // 设置圆角
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_payBtn.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(self.height/2, self.height/2)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = _payBtn.bounds;
- maskLayer.path = maskPath.CGPath;
- _payBtn.layer.mask = maskLayer;
- }
- return _payBtn;
- }
- -(void)setModel:(DRGoodDetailModel *)model
- {
- _model=model;
- if (model.is_coupon.integerValue != 1) {//无券的时候
-
- self.discountBtn.hidden=YES;
- self.payBtn.frame=CGRectMake(10, 5, SCREEN_WIDTH-20, self.height-10);
- [self paycorner:UIRectCornerBottomRight | UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerTopLeft];
- [self.payBtn setImage:[UIImage imageNamed:@"quan-2"] forState:UIControlStateNormal];
- [self.payBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:7];
- }else{
- [self.payBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
- self.discountBtn.hidden=NO;
- [self.discountBtn setTitle:[NSString stringWithFormat:@"%@元",model.coupon_price] forState:UIControlStateNormal];
- self.discountBtn.frame=CGRectMake(10, 5, buttonWidth/3, self.height-10);
- self.payBtn.frame=CGRectMake(10.5+buttonWidth/3, 5, buttonWidth/3*2, self.height-10);
-
- [self paycorner:UIRectCornerBottomRight | UIRectCornerTopRight];
- [self discountcorner];
-
-
- }
-
- }
- -(void)paycorner:(UIRectCorner)reconer
- {
- // 设置圆角
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_payBtn.bounds byRoundingCorners:reconer cornerRadii:CGSizeMake(self.height/2, self.height/2)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = _payBtn.bounds;
- maskLayer.path = maskPath.CGPath;
- _payBtn.layer.mask = maskLayer;
- }
- -(void)discountcorner
- {
- UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:_discountBtn.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(self.height/2, self.height/2)];
-
- CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
- maskLayer1.frame = _discountBtn.bounds;
- maskLayer1.path = maskPath1.CGPath;
- _discountBtn.layer.mask = maskLayer1;
-
- }
- @end
|