Skip to content

Commit

Permalink
Merge pull request #90 from xiangxiaopenyou/master
Browse files Browse the repository at this point in the history
v8.3.0
  • Loading branch information
jdbbjd authored Jul 21, 2022
2 parents 8110dbe + 9d92fc8 commit 1e0df2d
Show file tree
Hide file tree
Showing 285 changed files with 4,891 additions and 3,035 deletions.
418 changes: 418 additions & 0 deletions FUCommonUIComponent/FUCommonUIComponent.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>FUCommonUIComponent.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>13</integer>
</dict>
</dict>
</dict>
</plist>
21 changes: 21 additions & 0 deletions FUCommonUIComponent/FUCommonUIComponent/FUCommonUIComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// FUCommonUIComponent.h
// FUCommonUIComponent
//
// Created by 项林平 on 2022/6/17.
//

#import <Foundation/Foundation.h>
#import "FUSegmentBar.h"
#import "FUTipHUD.h"
#import "FUInsetsLabel.h"
#import "FUSlider.h"


//! Project version number for FUCommonUIComponent.
FOUNDATION_EXPORT double FUCommonUIComponentVersionNumber;

//! Project version string for FUCommonUIComponent.
FOUNDATION_EXPORT const unsigned char FUCommonUIComponentVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <FUCommonUIComponent/PublicHeader.h>
20 changes: 20 additions & 0 deletions FUCommonUIComponent/FUCommonUIComponent/FUCommonUIDefine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// FUCommonUIDefine.h
// FUCommonUIComponent
//
// Created by 项林平 on 2022/6/20.
//

#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>

#ifndef FUCommonUIDefine_h
#define FUCommonUIDefine_h

static inline UIImage * FUCommonUIImageNamed(NSString *name) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"FUCommonUIComponent" ofType:@"framework" inDirectory:@"Frameworks"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
return [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];;
}

#endif /* FUCommonUIDefine_h */
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// FUInsetsLabel.h
// FUCommonUIComponent
//
// Created by 项林平 on 2022/6/20.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface FUInsetsLabel : UILabel

- (instancetype)initWithFrame:(CGRect)frame insets:(UIEdgeInsets)insets;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// FUInsetsLabel.m
// FUCommonUIComponent
//
// Created by 项林平 on 2022/6/20.
//

#import "FUInsetsLabel.h"

@interface FUInsetsLabel ()

@property (nonatomic) UIEdgeInsets insets;

@end

@implementation FUInsetsLabel

- (instancetype)initWithFrame:(CGRect)frame {
return [self initWithFrame:frame insets:UIEdgeInsetsMake(8, 8, 8, 8)];
}

- (instancetype)initWithFrame:(CGRect)frame insets:(UIEdgeInsets)insets {
self = [super initWithFrame:frame];
if (self) {
self.insets = insets;
}
return self;
}

- (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.insets)];
}

- (CGSize)sizeThatFits:(CGSize)size {
CGSize fitSize = [super sizeThatFits:size];
fitSize.width += self.insets.left + self.insets.right;
fitSize.height += self.insets.top + self.insets.bottom;
return fitSize;
}

- (CGSize)intrinsicContentSize {
CGSize contentSize = [super intrinsicContentSize];
contentSize.width += self.insets.left + self.insets.right;
contentSize.height += self.insets.top + self.insets.bottom;
return contentSize;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ NS_ASSUME_NONNULL_BEGIN

@protocol FUSegmentBarDelegate <NSObject>

- (void)segmentBar:(FUSegmentBar *)segmentsView didSelectItemAtIndex:(NSUInteger)index;
- (void)segmentBar:(FUSegmentBar *)segmentBar didSelectItemAtIndex:(NSUInteger)index;

@optional
- (BOOL)segmentBar:(FUSegmentBar *)segmentBar shouldSelectItemAtIndex:(NSInteger)index;

@end

@interface FUSegmentBarConfigurations : NSObject

@property (nonatomic, strong) UIColor *normalTitleColor; // 普通颜色
@property (nonatomic, strong) UIColor *selectedTitleColor; // 选中颜色
@property (nonatomic, strong) UIFont *titleFont; // 字体

@end

Expand All @@ -35,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout NS_UNAVAILABLE;

/// 当前选中项索引(-1为取消选中)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ - (instancetype)init {
// 默认选中/未选中颜色
self.selectedTitleColor = [UIColor colorWithRed:94/255.0f green:199/255.0f blue:254/255.0f alpha:1.0];
self.normalTitleColor = [UIColor whiteColor];
self.titleFont = [UIFont systemFontOfSize:13];
}
return self;
}
Expand Down Expand Up @@ -46,12 +47,15 @@ - (instancetype)initWithFrame:(CGRect)frame titles:(NSArray<NSString *> *)titles
self = [super initWithFrame:frame collectionViewLayout:flowLayout];
if (self) {
self.backgroundColor = [UIColor colorWithRed:5/255.0 green:15/255.0 blue:20/255.0 alpha:1.0];
self.titles = [titles copy];
self.configuration = configuration;

self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;

self.titles = [titles copy];
self.configuration = configuration;
if (!self.configuration) {
self.configuration = [[FUSegmentBarConfigurations alloc] init];
}

// 计算宽度
NSMutableArray *tempWidths = [NSMutableArray arrayWithCapacity:self.titles.count];
if (self.titles.count < 6) {
Expand All @@ -63,13 +67,7 @@ - (instancetype)initWithFrame:(CGRect)frame titles:(NSArray<NSString *> *)titles
} else {
// 根据文字适配宽度
for (NSString *title in self.titles) {
NSString *resultString = [title copy];
if ([title componentsSeparatedByString:@"/"].count > 1) {
NSArray *tempTitles = [title componentsSeparatedByString:@"/"];
NSString *languageString = [[NSUserDefaults standardUserDefaults] objectForKey:@"appLanguage"];
resultString = [languageString isEqualToString:@"zh-Hans"] ? tempTitles[0] : tempTitles[1];
}
CGSize nameSize = [resultString sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13]}];
CGSize nameSize = [title sizeWithAttributes:@{NSFontAttributeName : self.configuration.titleFont}];
[tempWidths addObject:@(nameSize.width + 20)];
}
}
Expand Down Expand Up @@ -107,13 +105,8 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FUSegmentsBarCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kFUSegmentCellIdentifierKey forIndexPath:indexPath];
NSString *titleString = self.titles[indexPath.item];
if ([self.titles[indexPath.item] componentsSeparatedByString:@"/"].count > 1) {
NSArray *titles = [self.titles[indexPath.item] componentsSeparatedByString:@"/"];
NSString *languageString = [[NSUserDefaults standardUserDefaults] objectForKey:@"appLanguage"];
titleString = [languageString isEqualToString:@"zh-Hans"] ? titles[0] : titles[1];
}
cell.segmentTitleLabel.text = titleString;
cell.segmentTitleLabel.text = self.titles[indexPath.item];
cell.segmentTitleLabel.font = self.configuration.titleFont;
cell.segmentNormalTitleColor = self.configuration.normalTitleColor;
cell.segmentSelectedTitleColor = self.configuration.selectedTitleColor;
return cell;
Expand All @@ -128,6 +121,13 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
}
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.segmentDelegate && [self.segmentDelegate respondsToSelector:@selector(segmentBar:shouldSelectItemAtIndex:)]) {
return [self.segmentDelegate segmentBar:self shouldSelectItemAtIndex:indexPath.item];
}
return YES;
}

#pragma mark - Collection view delegate flow layout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
Expand All @@ -145,9 +145,9 @@ - (instancetype)initWithFrame:(CGRect)frame {
if (self) {
self.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.segmentTitleLabel];
[self.segmentTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
NSLayoutConstraint *titleLabelCenterX = [NSLayoutConstraint constraintWithItem:self.segmentTitleLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
NSLayoutConstraint *titleLabelCenterY = [NSLayoutConstraint constraintWithItem:self.segmentTitleLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
[self.contentView addConstraints:@[titleLabelCenterX, titleLabelCenterY]];
}
return self;
}
Expand All @@ -171,6 +171,7 @@ - (UILabel *)segmentTitleLabel {
_segmentTitleLabel.textColor = [UIColor whiteColor];
_segmentTitleLabel.font = [UIFont systemFontOfSize:13];
_segmentTitleLabel.textAlignment = NSTextAlignmentCenter;
_segmentTitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
}
return _segmentTitleLabel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@interface FUSlider : UISlider

/// 零点是否在中间
/// 零点是否在中间,默认为NO
@property (nonatomic, assign, getter=isBidirection) BOOL bidirection;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "FUSlider.h"
#import "UIImage+demobar.h"
#import "FUCommonUIDefine.h"

@interface FUSlider ()

Expand All @@ -26,37 +26,30 @@ @implementation FUSlider

- (void)awakeFromNib {
[super awakeFromNib];

[self setThumbImage:[UIImage imageWithName:@"slider_dot"] forState:UIControlStateNormal];

[self setMaximumTrackTintColor:[UIColor whiteColor]];
[self setMinimumTrackTintColor:[UIColor colorWithRed:94/255.0 green:199/255.0 blue:254/255.0 alpha:1]];
[self addSubview:self.tipBackgroundImageView];
[self addSubview:self.tipLabel];
[self addSubview:self.trackView];
[self addSubview:self.middleLine];
[self configureUI];
}

- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {

[self setThumbImage:[UIImage imageWithName:@"slider_dot"] forState:UIControlStateNormal];
[self setMaximumTrackTintColor:[UIColor whiteColor]];
[self setMinimumTrackTintColor:[UIColor colorWithRed:94/255.0 green:199/255.0 blue:254/255.0 alpha:1]];
[self addSubview:self.tipBackgroundImageView];
[self addSubview:self.tipLabel];
[self addSubview:self.trackView];
[self addSubview:self.middleLine];

[self configureUI];
}
return self;
}

- (void)configureUI {
[self setThumbImage:FUCommonUIImageNamed(@"slider_dot") forState:UIControlStateNormal];
[self setMaximumTrackTintColor:[UIColor whiteColor]];
[self setMinimumTrackTintColor:[UIColor colorWithRed:94/255.0 green:199/255.0 blue:254/255.0 alpha:1]];
[self addSubview:self.tipBackgroundImageView];
[self addSubview:self.tipLabel];
[self addSubview:self.trackView];
[self addSubview:self.middleLine];
}

-(void)layoutSubviews {
[super layoutSubviews];

self.middleLine.frame = CGRectMake(CGRectGetWidth(self.bounds)/2.0 - 1, CGRectGetHeight(self.bounds)/2.0 - 4, 2, 8);

[self setValue:self.value animated:NO];
}

Expand Down Expand Up @@ -84,7 +77,6 @@ - (void)setValue:(float)value animated:(BOOL)animated {
width = -width ;
}
CGFloat originX = currentValue > 0 ? CGRectGetWidth(self.bounds) / 2.0 : CGRectGetWidth(self.bounds) / 2.0 - width ;

self.trackView.frame = CGRectMake(originX, CGRectGetHeight(self.frame)/2.0 - 2, width, 4.0);
} else {
self.tipLabel.text = [NSString stringWithFormat:@"%d",(int)(value * 100)];
Expand All @@ -105,7 +97,7 @@ - (void)setValue:(float)value animated:(BOOL)animated {

- (UIImageView *)tipBackgroundImageView {
if (!_tipBackgroundImageView) {
UIImage *bgImage = [UIImage imageWithName:@"slider_tip_bg"];
UIImage *bgImage = FUCommonUIImageNamed(@"slider_tip_background");
_tipBackgroundImageView = [[UIImageView alloc] initWithImage:bgImage];
_tipBackgroundImageView.frame = CGRectMake(0, -bgImage.size.height, bgImage.size.width, bgImage.size.height);
_tipBackgroundImageView.hidden = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface FUTipHUD : NSObject

/// 文字提示(默认3秒后自动消失)
/// @param tipsString 文字
+ (void)showTips:(NSString *)tipsString;

@end

@interface FUInsertsLabel : UILabel

- (instancetype)initWithFrame:(CGRect)frame insets:(UIEdgeInsets)insets;
/// 文字提示
/// @param tipsString 文字
/// @param delay 自动消失时间,单位: 秒
+ (void)showTips:(NSString *)tipsString dismissWithDelay:(NSTimeInterval)delay;

@end

Expand Down
Loading

0 comments on commit 1e0df2d

Please sign in to comment.