|
@@ -5,10 +5,10 @@
|
|
// Created by 邢铖 on 2023/6/6.
|
|
// Created by 邢铖 on 2023/6/6.
|
|
//
|
|
//
|
|
|
|
|
|
-#import "XCComCategorySelectView.h"
|
|
|
|
-#import <XCPublicModule/XCPublicModule.h>
|
|
|
|
|
|
+#import "XCBCCategorySelectView.h"
|
|
#import <Masonry/Masonry.h>
|
|
#import <Masonry/Masonry.h>
|
|
-#import "OCUtils.h"
|
|
|
|
|
|
+
|
|
|
|
+#define clamp(t, min, max) ((min) + ((max) - (min)) * (t))
|
|
|
|
|
|
static char kXCBCCategorySelectTitleViewKVOKey[] = "kXCBCCategorySelectTitleViewKVOKey";
|
|
static char kXCBCCategorySelectTitleViewKVOKey[] = "kXCBCCategorySelectTitleViewKVOKey";
|
|
|
|
|
|
@@ -44,22 +44,27 @@ static char kXCBCCategorySelectTitleViewKVOKey[] = "kXCBCCategorySelectTitleView
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (UIColor *)makeColorWithDiff:(CGFloat)diff alpha:(CGFloat)alpha {
|
|
|
|
+ return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
|
|
|
|
+ if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
|
|
|
|
+ return [UIColor colorWithWhite:diff alpha:alpha];
|
|
|
|
+ } else {
|
|
|
|
+ return [UIColor colorWithWhite:1 - diff alpha:alpha];
|
|
|
|
+ }
|
|
|
|
+ }];
|
|
|
|
+}
|
|
|
|
+
|
|
- (void)updateSelectable {
|
|
- (void)updateSelectable {
|
|
CGFloat maximumSize = 20;
|
|
CGFloat maximumSize = 20;
|
|
CGFloat minimumSize = 15;
|
|
CGFloat minimumSize = 15;
|
|
UIFontWeight maximumWeight = UIFontWeightHeavy;
|
|
UIFontWeight maximumWeight = UIFontWeightHeavy;
|
|
UIFontWeight minimumWeight = UIFontWeightThin;
|
|
UIFontWeight minimumWeight = UIFontWeightThin;
|
|
-#define clamp(t, min, max) ((min) + ((max) - (min)) * (t))
|
|
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:self.categoryTitle];
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:self.categoryTitle];
|
|
NSRange allRange = NSMakeRange(0, attr.length);
|
|
NSRange allRange = NSMakeRange(0, attr.length);
|
|
[attr setAttributes:@{
|
|
[attr setAttributes:@{
|
|
- NSForegroundColorAttributeName : [UIColor grayScaleWithDiff:[self clampValue:self.selectPrecentage
|
|
|
|
- withBoundLeft:0.4
|
|
|
|
- andBoundRight:1]
|
|
|
|
- alpha:1]
|
|
|
|
|
|
+ NSForegroundColorAttributeName : [self makeColorWithDiff:clamp(self.selectPrecentage, 0.4, 1) alpha:1]
|
|
// NSFontAttributeName : [UIFont systemFontOfSize:clamp(self.selectPrecentage, minimumSize, maximumSize)]
|
|
// NSFontAttributeName : [UIFont systemFontOfSize:clamp(self.selectPrecentage, minimumSize, maximumSize)]
|
|
} range:allRange];
|
|
} range:allRange];
|
|
-#undef clamp
|
|
|
|
[self setAttributedTitle:attr forState:UIControlStateNormal];
|
|
[self setAttributedTitle:attr forState:UIControlStateNormal];
|
|
[self layoutSubviews];
|
|
[self layoutSubviews];
|
|
}
|
|
}
|
|
@@ -119,7 +124,7 @@ static char kXCBCCategorySelectViewKVOKey[] = "kXCBCCategorySelectViewKVOKey";
|
|
- (UIView *)indicatorView {
|
|
- (UIView *)indicatorView {
|
|
if (!_indicatorView) {
|
|
if (!_indicatorView) {
|
|
_indicatorView = [UIView new];
|
|
_indicatorView = [UIView new];
|
|
- _indicatorView.backgroundColor = UIColor.systemOrangeColor;
|
|
|
|
|
|
+ _indicatorView.backgroundColor = UIColor.linkColor;
|
|
_indicatorView.layer.masksToBounds = true;
|
|
_indicatorView.layer.masksToBounds = true;
|
|
_indicatorView.layer.cornerRadius = 1.5;
|
|
_indicatorView.layer.cornerRadius = 1.5;
|
|
}
|
|
}
|
|
@@ -162,9 +167,9 @@ static char kXCBCCategorySelectViewKVOKey[] = "kXCBCCategorySelectViewKVOKey";
|
|
for (NSString *categoryName in self.categoryNames) {
|
|
for (NSString *categoryName in self.categoryNames) {
|
|
XCBCCategorySelectTitleView *button = [XCBCCategorySelectTitleView new];
|
|
XCBCCategorySelectTitleView *button = [XCBCCategorySelectTitleView new];
|
|
button.categoryTitle = categoryName;
|
|
button.categoryTitle = categoryName;
|
|
- XC_WEAKIFY_SELF;
|
|
|
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
button.touchBlock = ^{
|
|
button.touchBlock = ^{
|
|
- XC_STRONG_SELF;
|
|
|
|
|
|
+ typeof(self) self = weakSelf;
|
|
[self userDidSelectCategoryAtIndex:index];
|
|
[self userDidSelectCategoryAtIndex:index];
|
|
};
|
|
};
|
|
[self.stackView addArrangedSubview:button];
|
|
[self.stackView addArrangedSubview:button];
|
|
@@ -196,12 +201,8 @@ static char kXCBCCategorySelectViewKVOKey[] = "kXCBCCategorySelectViewKVOKey";
|
|
CGFloat leftRightPercentageValue = self.selectedIndex - leftObjectIndex;
|
|
CGFloat leftRightPercentageValue = self.selectedIndex - leftObjectIndex;
|
|
XCBCCategorySelectTitleView *leftView = self.stackView.arrangedSubviews[leftObjectIndex];
|
|
XCBCCategorySelectTitleView *leftView = self.stackView.arrangedSubviews[leftObjectIndex];
|
|
XCBCCategorySelectTitleView *rightView = self.stackView.arrangedSubviews[rightObjectIndex];
|
|
XCBCCategorySelectTitleView *rightView = self.stackView.arrangedSubviews[rightObjectIndex];
|
|
- CGFloat selectorWidth = [self clampValue:leftRightPercentageValue
|
|
|
|
- withBoundLeft:leftView.frame.size.width
|
|
|
|
- andBoundRight:rightView.frame.size.width];
|
|
|
|
- CGFloat selectorLeft = [self clampValue:leftRightPercentageValue
|
|
|
|
- withBoundLeft:leftView.frame.origin.x
|
|
|
|
- andBoundRight:rightView.frame.origin.x];
|
|
|
|
|
|
+ CGFloat selectorWidth = clamp(leftRightPercentageValue, leftView.frame.size.width, rightView.frame.size.width);
|
|
|
|
+ CGFloat selectorLeft = clamp(leftRightPercentageValue, leftView.frame.origin.x, rightView.frame.origin.x);
|
|
leftView.selectPrecentage = 1 - leftRightPercentageValue;
|
|
leftView.selectPrecentage = 1 - leftRightPercentageValue;
|
|
rightView.selectPrecentage = leftRightPercentageValue;
|
|
rightView.selectPrecentage = leftRightPercentageValue;
|
|
[self.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
[self.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
|