Skip to content

Commit

Permalink
666
Browse files Browse the repository at this point in the history
  • Loading branch information
孟宪亮 committed Jan 8, 2020
1 parent b2dd0de commit 6df35a9
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 0 deletions.
19 changes: 19 additions & 0 deletions XLChannelControl/XLChannelControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// XLChannelControl.h
// XLChannelControlDemo
//
// Created by MengXianLiang on 2017/3/3.
// Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef void(^XLChannelBlock)(NSArray *enabledTitles,NSArray *disabledTitles);

@interface XLChannelControl : NSObject

+ (XLChannelControl*)shareControl;

- (void)showChannelViewWithEnabledTitles:(NSArray*)enabledTitles disabledTitles:(NSArray*)disabledTitles finish:(XLChannelBlock)block;

@end
79 changes: 79 additions & 0 deletions XLChannelControl/XLChannelControl.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// XLChannelControl.m
// XLChannelControlDemo
//
// Created by MengXianLiang on 2017/3/3.
// Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import "XLChannelControl.h"
#import "XLChannelView.h"

@interface XLChannelControl ()

@property (nonatomic, strong) UINavigationController *nav;

@property (nonatomic, strong) XLChannelView *channelView;

@property (nonatomic, strong) XLChannelBlock block;

@end

@implementation XLChannelControl

+(XLChannelControl*)shareControl{
static XLChannelControl *control = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
control = [[XLChannelControl alloc] init];
});
return control;
}

- (instancetype)init {
if (self = [super init]) {
[self buildChannelView];
}
return self;
}

- (void)buildChannelView {

self.channelView = [[XLChannelView alloc] initWithFrame:[UIScreen mainScreen].bounds];

self.nav = [[UINavigationController alloc] initWithRootViewController:[UIViewController new]];
self.nav.navigationBar.tintColor = [UIColor blackColor];
self.nav.topViewController.title = @"频道管理";
self.nav.topViewController.view = self.channelView;
self.nav.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(backMethod)];
}

- (void)backMethod {
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.nav.view.frame;
frame.origin.y = - self.nav.view.bounds.size.height;
self.nav.view.frame = frame;
}completion:^(BOOL finished) {
[self.nav.view removeFromSuperview];
}];
self.block(self.channelView.enabledTitles,self.channelView.disabledTitles);
}

- (void)showChannelViewWithEnabledTitles:(NSArray*)enabledTitles disabledTitles:(NSArray*)disabledTitles finish:(XLChannelBlock)block {
self.block = block;
self.channelView.enabledTitles = [NSMutableArray arrayWithArray:enabledTitles];
self.channelView.disabledTitles = [NSMutableArray arrayWithArray:disabledTitles];
[self.channelView reloadData];

CGRect frame = self.nav.view.frame;
frame.origin.y = - self.nav.view.bounds.size.height;
self.nav.view.frame = frame;
self.nav.view.alpha = 0;
[[UIApplication sharedApplication].keyWindow addSubview:self.nav.view];
[UIView animateWithDuration:0.3 animations:^{
self.nav.view.alpha = 1;
self.nav.view.frame = [UIScreen mainScreen].bounds;
}];
}

@end
17 changes: 17 additions & 0 deletions XLChannelControl/XLChannelHeader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// XLChannelHeaderView.h
// XLChannelControlDemo
//
// Created by MengXianLiang on 2017/3/3.
// Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface XLChannelHeader : UICollectionReusableView

@property (copy,nonatomic) NSString *title;

@property (copy,nonatomic) NSString *subTitle;

@end
58 changes: 58 additions & 0 deletions XLChannelControl/XLChannelHeader.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// XLChannelHeaderView.m
// XLChannelControlDemo
//
// Created by MengXianLiang on 2017/3/3.
// Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import "XLChannelHeader.h"

@interface XLChannelHeader ()

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UILabel *subtitleLabel;

@end

@implementation XLChannelHeader

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

-(void)buildUI
{
CGFloat marginX = 15.0f;

CGFloat labelWidth = (self.bounds.size.width - 2*marginX)/2.0f;

self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(marginX, 0, labelWidth, self.bounds.size.height)];
self.titleLabel.textColor = [UIColor blackColor];
[self addSubview:self.titleLabel];

self.subtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelWidth + marginX, 0, labelWidth, self.bounds.size.height)];
self.subtitleLabel.textColor = [UIColor lightGrayColor];
self.subtitleLabel.textAlignment = NSTextAlignmentRight;
self.subtitleLabel.font = [UIFont systemFontOfSize:15.0f];
[self addSubview:self.subtitleLabel];
}

-(void)setTitle:(NSString *)title
{
_title = title;
self.titleLabel.text = title;
}

-(void)setSubTitle:(NSString *)subTitle
{
_subTitle = subTitle;
self.subtitleLabel.text = subTitle;
}

@end
21 changes: 21 additions & 0 deletions XLChannelControl/XLChannelItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// XLChannelItem.h
// XLChannelControlDemo
//
// Created by MengXianLiang on 2017/3/3.
// Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface XLChannelItem : UICollectionViewCell
//标题
@property (nonatomic, copy) NSString *title;

//是否正在移动状态
@property (nonatomic, assign) BOOL isMoving;

//是否被固定
@property (nonatomic, assign) BOOL isFixed;

@end
111 changes: 111 additions & 0 deletions XLChannelControl/XLChannelItem.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// XLChannelItem.m
// XLChannelControlDemo
//
// Created by MengXianLiang on 2017/3/3.
// Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import "XLChannelItem.h"

@interface XLChannelItem ()

@property (nonatomic, strong) UILabel *textLabel;

@property (nonatomic, strong) CAShapeLayer *borderLayer;

@end

@implementation XLChannelItem

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

-(void)initUI
{
self.userInteractionEnabled = true;
self.layer.cornerRadius = 5.0f;
self.backgroundColor = [self backgroundColor];

self.textLabel = [UILabel new];
self.textLabel.frame = self.bounds;
self.textLabel.textAlignment = NSTextAlignmentCenter;
self.textLabel.textColor = [self textColor];
self.textLabel.adjustsFontSizeToFitWidth = true;
self.textLabel.userInteractionEnabled = true;
[self addSubview:self.textLabel];

[self addBorderLayer];
}

-(void)addBorderLayer{
self.borderLayer = [CAShapeLayer layer];
self.borderLayer.bounds = self.bounds;
self.borderLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
self.borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.borderLayer.bounds cornerRadius:self.layer.cornerRadius].CGPath;
self.borderLayer.lineWidth = 1;
self.borderLayer.lineDashPattern = @[@5, @3];
self.borderLayer.fillColor = [UIColor clearColor].CGColor;
self.borderLayer.strokeColor = [self backgroundColor].CGColor;
[self.layer addSublayer:self.borderLayer];
self.borderLayer.hidden = true;
}

-(void)layoutSubviews
{
[super layoutSubviews];
self.textLabel.frame = self.bounds;
}

#pragma mark -
#pragma mark 配置方法

-(UIColor*)backgroundColor{
return [UIColor colorWithRed:241/255.0f green:241/255.0f blue:241/255.0f alpha:1];
}

-(UIColor*)textColor{
return [UIColor colorWithRed:40/255.0f green:40/255.0f blue:40/255.0f alpha:1];
}

-(UIColor*)lightTextColor{
return [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];
}

#pragma mark -
#pragma mark Setter

-(void)setTitle:(NSString *)title
{
_title = title;
self.textLabel.text = title;
}

-(void)setIsMoving:(BOOL)isMoving
{
_isMoving = isMoving;
if (_isMoving) {
self.backgroundColor = [UIColor clearColor];
self.borderLayer.hidden = false;
}else{
self.backgroundColor = [self backgroundColor];
self.borderLayer.hidden = true;
}
}

-(void)setIsFixed:(BOOL)isFixed{
_isFixed = isFixed;
if (isFixed) {
self.textLabel.textColor = [self lightTextColor];
}else{
self.textLabel.textColor = [self textColor];
}
}

@end
19 changes: 19 additions & 0 deletions XLChannelControl/XLChannelView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// XLChannelView.h
// XLChannelControlDemo
//
// Created by MengXianLiang on 2017/3/3.
// Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface XLChannelView : UIView

@property (nonatomic, strong) NSMutableArray *enabledTitles;

@property (nonatomic,strong) NSMutableArray *disabledTitles;

-(void)reloadData;

@end
Loading

0 comments on commit 6df35a9

Please sign in to comment.