2023-09-01 18:58:41 +08:00
|
|
|
|
//
|
|
|
|
|
// PIHoemCategoryTitleView.m
|
|
|
|
|
// YuMi
|
|
|
|
|
//
|
|
|
|
|
// Created by duoban on 2023/9/1.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "PIHoemCategoryTitleView.h"
|
|
|
|
|
@interface PIHoemCategoryTitleView()
|
|
|
|
|
@property(nonatomic,strong) UIButton *fristBnt;
|
|
|
|
|
@property(nonatomic,strong) UIButton *secondBnt;
|
|
|
|
|
@property(nonatomic,strong) UIImageView *lineImage;
|
|
|
|
|
@end
|
|
|
|
|
@implementation PIHoemCategoryTitleView
|
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
|
if(self){
|
|
|
|
|
[self installUI];
|
|
|
|
|
[self installConstraints];
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
-(void)installUI{
|
|
|
|
|
UIButton *b = [UIButton new];
|
|
|
|
|
[self addSubview:b];
|
|
|
|
|
[b mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.equalTo(self);
|
|
|
|
|
}];
|
|
|
|
|
[self addSubview:self.lineImage];
|
|
|
|
|
[self addSubview:self.fristBnt];
|
|
|
|
|
[self addSubview:self.secondBnt];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(void)installConstraints{
|
|
|
|
|
|
|
|
|
|
[self.fristBnt mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.leading.mas_equalTo(kGetScaleWidth(15));
|
|
|
|
|
make.centerY.equalTo(self);
|
|
|
|
|
make.height.mas_equalTo(kGetScaleWidth(22));
|
|
|
|
|
}];
|
|
|
|
|
[self.secondBnt mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.leading.equalTo(self.fristBnt.mas_trailing).mas_offset(kGetScaleWidth(24));
|
|
|
|
|
make.centerY.equalTo(self);
|
|
|
|
|
make.height.mas_equalTo(kGetScaleWidth(22));
|
|
|
|
|
}];
|
|
|
|
|
[self.lineImage mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.width.mas_equalTo(kGetScaleWidth(36));
|
|
|
|
|
make.height.mas_equalTo(kGetScaleWidth(8));
|
|
|
|
|
make.bottom.equalTo(self.fristBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
|
|
|
|
|
make.trailing.equalTo(self.fristBnt.mas_trailing);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
-(void)chooseItem:(UIButton *)sender{
|
|
|
|
|
self.fristBnt.titleLabel.font = sender == self.fristBnt ? kFontSemibold(16):kFontRegular(14);
|
|
|
|
|
self.secondBnt.titleLabel.font = sender != self.fristBnt ? kFontSemibold(16):kFontRegular(14);
|
|
|
|
|
self.fristBnt.selected = sender == self.fristBnt;
|
|
|
|
|
self.secondBnt.selected = sender != self.fristBnt;
|
|
|
|
|
if(self.fristBnt == sender){
|
2023-09-25 16:02:57 +08:00
|
|
|
|
|
|
|
|
|
if(self.scrolledHandle){
|
|
|
|
|
self.scrolledHandle(0);
|
2023-09-01 18:58:41 +08:00
|
|
|
|
}
|
|
|
|
|
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.width.mas_equalTo(kGetScaleWidth(36));
|
|
|
|
|
make.height.mas_equalTo(kGetScaleWidth(8));
|
|
|
|
|
make.bottom.equalTo(self.fristBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
|
|
|
|
|
make.trailing.equalTo(self.fristBnt.mas_trailing);
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-25 16:02:57 +08:00
|
|
|
|
|
|
|
|
|
if(self.scrolledHandle){
|
|
|
|
|
self.scrolledHandle(1);
|
2023-09-01 18:58:41 +08:00
|
|
|
|
}
|
|
|
|
|
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.width.mas_equalTo(kGetScaleWidth(36));
|
|
|
|
|
make.height.mas_equalTo(kGetScaleWidth(8));
|
|
|
|
|
make.bottom.equalTo(self.secondBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
|
|
|
|
|
make.trailing.equalTo(self.secondBnt.mas_trailing);
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
2023-09-25 16:02:57 +08:00
|
|
|
|
- (void)setIndex:(NSInteger)index{
|
2023-09-01 18:58:41 +08:00
|
|
|
|
_index = index;
|
|
|
|
|
self.fristBnt.titleLabel.font = _index == 0 ? kFontSemibold(16):kFontRegular(14);
|
|
|
|
|
self.secondBnt.titleLabel.font = _index == 1 ? kFontSemibold(16):kFontRegular(14);
|
|
|
|
|
self.fristBnt.selected = _index == 0;
|
|
|
|
|
self.secondBnt.selected = _index == 1;
|
|
|
|
|
if(_index == 0){
|
|
|
|
|
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.width.mas_equalTo(kGetScaleWidth(36));
|
|
|
|
|
make.height.mas_equalTo(kGetScaleWidth(8));
|
|
|
|
|
make.bottom.equalTo(self.fristBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
|
|
|
|
|
make.trailing.equalTo(self.fristBnt.mas_trailing);
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.width.mas_equalTo(kGetScaleWidth(36));
|
|
|
|
|
make.height.mas_equalTo(kGetScaleWidth(8));
|
|
|
|
|
make.bottom.equalTo(self.secondBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
|
|
|
|
|
make.trailing.equalTo(self.secondBnt.mas_trailing);
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
#pragma mark - 懒加载
|
|
|
|
|
- (UIButton *)fristBnt{
|
|
|
|
|
if(!_fristBnt){
|
|
|
|
|
_fristBnt = [UIButton new];
|
|
|
|
|
[_fristBnt setTitle:YMLocalizedString(@"XPNewHomeViewController0") forState:UIControlStateNormal];
|
|
|
|
|
[_fristBnt setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
|
|
|
|
|
[_fristBnt setTitleColor:UIColorFromRGB(0x767585) forState:UIControlStateNormal];
|
|
|
|
|
_fristBnt.selected = YES;
|
|
|
|
|
_fristBnt.titleLabel.font = kFontSemibold(16);
|
|
|
|
|
[_fristBnt addTarget:self action:@selector(chooseItem:) forControlEvents:UIControlEventTouchUpInside];
|
2023-09-07 19:01:31 +08:00
|
|
|
|
[_fristBnt setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
2023-09-01 18:58:41 +08:00
|
|
|
|
}
|
|
|
|
|
return _fristBnt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIButton *)secondBnt{
|
|
|
|
|
if(!_secondBnt){
|
|
|
|
|
_secondBnt = [UIButton new];
|
|
|
|
|
[_secondBnt setTitle:YMLocalizedString(@"XPNewHomeViewController1") forState:UIControlStateNormal];
|
|
|
|
|
[_secondBnt setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
|
|
|
|
|
[_secondBnt setTitleColor:UIColorFromRGB(0x767585) forState:UIControlStateNormal];
|
|
|
|
|
_secondBnt.titleLabel.font = kFontRegular(14);
|
|
|
|
|
[_secondBnt addTarget:self action:@selector(chooseItem:) forControlEvents:UIControlEventTouchUpInside];
|
2023-09-07 19:01:31 +08:00
|
|
|
|
[_secondBnt setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
2023-09-01 18:58:41 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return _secondBnt;
|
|
|
|
|
}
|
|
|
|
|
- (UIImageView *)lineImage{
|
|
|
|
|
if(!_lineImage){
|
|
|
|
|
_lineImage = [UIImageView new];
|
|
|
|
|
_lineImage.image = kImage(@"home_slider_bg");
|
|
|
|
|
}
|
|
|
|
|
return _lineImage;
|
|
|
|
|
}
|
|
|
|
|
//- (void)layoutSubviews{
|
|
|
|
|
// [super layoutSubviews];
|
|
|
|
|
//
|
|
|
|
|
// //部分使用者为了适配不同的手机屏幕尺寸,JXCategoryView的宽高比要求保持一样,所以它的高度就会因为不同宽度的屏幕而不一样。计算出来的高度,有时候会是位数很长的浮点数,如果把这个高度设置给UICollectionView就会触发内部的一个错误。所以,为了规避这个问题,在这里对高度统一向下取整。
|
|
|
|
|
// //如果向下取整导致了你的页面异常,请自己重新设置JXCategoryView的高度,保证为整数即可。
|
|
|
|
|
//
|
|
|
|
|
// CGRect targetFrame = CGRectMake(0, 0, self.bounds.size.width - kGetScaleWidth(159), floor(self.bounds.size.height));
|
|
|
|
|
// self.collectionView.frame = targetFrame;
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
@end
|