123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- //
- // FKProSegmentView.m
- // FirstLink
- //
- // Created by jack on 16/8/13.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKProSegmentView.h"
- @interface FKProSegmentView ()
- @property (nonatomic, strong) UILabel *leftLabel;
- @property (nonatomic, strong) UILabel *rightLabel;
- @property (nonatomic, strong) UIView *horLine;
- @property (nonatomic, copy) void(^indexChange)(NSInteger index);
- @property (nonatomic, strong) MASConstraint *constToCenterX;
- @end
- @implementation FKProSegmentView
- - (instancetype)initWithIndexChange:(void(^)(NSInteger index))indexChange{
- if (self = [super init]) {
- [self addAllSubviews];
- self.indexChange = indexChange;
- }
- return self;
- }
- - (void)addAllSubviews{
-
- self.backgroundColor = [UIColor whiteColor];
-
- UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
-
- leftBtn.tag = 0;
- rightBtn.tag = 1;
-
- [leftBtn addTarget:self
- action:@selector(changeIndex:)
- forControlEvents:UIControlEventTouchUpInside];
- [rightBtn addTarget:self
- action:@selector(changeIndex:)
- forControlEvents:UIControlEventTouchUpInside];
-
- [self addSubview:self.leftLabel];
- [self addSubview:self.rightLabel];
- [self addSubview:self.horLine];
- [self addSubview:leftBtn];
- [self addSubview:rightBtn];
-
- [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.mas_centerX).offset(- 50);
- make.centerY.equalTo(self);
- }];
-
- [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.mas_centerX).offset(50);
- make.centerY.equalTo(self);
- }];
-
- [self.horLine mas_makeConstraints:^(MASConstraintMaker *make) {
- self.constToCenterX = make.centerX.equalTo(self.leftLabel);
- make.bottom.equalTo(self).offset(- 5);
- make.size.mas_equalTo(CGSizeMake(60, 2));
- }];
-
- [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.equalTo(self);
- make.right.equalTo(self.mas_centerX);
- }];
-
- [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.bottom.equalTo(self);
- make.left.equalTo(self.mas_centerX);
- }];
- }
- - (void)changeIndex:(UIButton *)sender{
-
- if (sender.tag == self.horLine.tag) return;
-
- self.leftLabel.textColor = UIColorFromRGB(0x666666);
- self.rightLabel.textColor = UIColorFromRGB(0x666666);
-
- UILabel *targetLabel = self.leftLabel;
- if (sender.tag == 1) targetLabel = self.rightLabel;
-
- targetLabel.textColor = UIColorFromRGB(0x333333);
-
-
- [self.horLine mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(targetLabel);
- make.bottom.equalTo(self).offset(- 5);
- make.size.mas_equalTo(CGSizeMake(60, 2));
- }];
- // self.constToCenterX.equalTo(targetLabel);
- self.horLine.tag = sender.tag;
-
- if (self.indexChange) {
- self.indexChange(sender.tag);
- }
- }
- - (NSInteger)currentIndex{
- return self.horLine.tag;
- }
- - (UILabel *)leftLabel{
- if (_leftLabel == nil) {
- _leftLabel = [[UILabel alloc]init];
- _leftLabel.textColor = UIColorFromRGB(0x333333);
- _leftLabel.font = [UIFont systemFontOfSize:14];
- _leftLabel.text = @"商品详情";
- }
- return _leftLabel;
- }
- - (UILabel *)rightLabel{
- if (_rightLabel == nil) {
- _rightLabel = [[UILabel alloc]init];
- _rightLabel.textColor = UIColorFromRGB(0x666666);
- _rightLabel.font = [UIFont systemFontOfSize:14];
- _rightLabel.text = @"温馨提示";
- }
- return _rightLabel;
- }
- - (UIView *)horLine{
- if (_horLine == nil) {
- _horLine = [[UIView alloc]init];
- _horLine.backgroundColor = UIColorFromRGB(0xff6362);
- _horLine.tag = 0;
- }
- return _horLine;
- }
- @end
|