//
// TFScrollNavigationBar.h
// 2015506-02ScrollNavigation框架
//
// Created by appple on 15-5-6.
// Copyright (c) 2015年 appple. All rights reserved.
//
#import <UIKit/UIKit.h>
//自定义导航栏
@class TFScrollNavigationBar;
@protocol TFScrollNavigationBar <NSObject>
@optional
/** 选中一个按钮后告诉代理 */
- (void)scrollNavigationBar:(TFScrollNavigationBar *)scrollNavigationBar DidSelectedButton : (UIButton *)button;
@end
@interface TFScrollNavigationBar : UIView
/** 代理 */
@property (nonatomic , weak) id<TFScrollNavigationBar> delegate;
/** 标题scrollView */
@property (nonatomic , weak , readonly) UIScrollView * titleScrollView;
/** 右侧辅助按钮数组 */
@property (nonatomic , strong , readonly) NSArray * accessoryButtons;
/** 标题显示字体的大小 (根据字体计算标题长度 , 该参数为nil时默认跟随系统)*/
@property (nonatomic , strong) UIFont *title_font;
/** 标题显示文字及下划线的颜色 */
@property (nonatomic , strong) UIColor * titleSelectedColor;
/** 标题显示文字常规颜色 */
@property (nonatomic , strong) UIColor * titleNomalColor;
/** 当前选中的按钮 */
@property (nonatomic , weak , readonly) UIButton * selectedButton;
/** 标题按钮数组 */
@property (nonatomic , strong , readonly) NSMutableArray * titleButtons;
/** 根据传进来的控制器数组进行初始化 (本方法只为了拿到控制器的标题,不强引用控制器) */
- (instancetype)initWithControllers : (NSArray *) controllers;
/** 添加右侧辅助按钮 (数组形式 , 建议最多添加2个 ) */
- (void)addAccessoryButtons:(NSArray *) accessoryButtons;
/** 设置导航栏中的控制器标题按钮字体颜色及尺寸 */
- (void)setButtonTitleWithNomalColor : (UIColor *)nomalColor AndSelectedColor : (UIColor *)selectedColor AndTitleFont : (UIFont *)font;
/** 设置按钮点击事件 (外部调用该方法只为了选中传入的按钮) */
- (void)clickButton : (UIButton *)button;
/** 根据数组item的位置及比例滚动下划线 */
- (void)scrollUnderLineToItemAtIndex : (NSInteger)index WithScale : (CGFloat)scale;
@end
//
// TFScrollNavigationBar.m
// 2015506-02ScrollNavigation框架
//
// Created by appple on 15-5-6.
// Copyright (c) 2015年 appple. All rights reserved.
//
#import "TFScrollNavigationBar.h"
#define Default_Selected_Color [UIColor colorWithRed:0/255.0 green:122/255.0 blue:255/255.0 alpha:1]
#define Default_Nomal_Color [UIColor whiteColor]
#define DurationTime 0.3
#define titleFont [UIFont systemFontOfSize:13.0]
#define subTitleFont [UIFont systemFontOfSize:5.0]
#define commentFont [UIFont systemFontOfSize:5.0]
/** 按钮标题文字之间的间距 */
#define Button_Inset 20.0
@interface TFScrollNavigationBar ()
/** 标题scrollView (重写属性的目的 : 外界只读 , 内部可读可写) */
@property (nonatomic , weak , readwrite) UIScrollView * titleScrollView;
/** 右侧辅助按钮数组 (重写属性的目的 : 外界只读 , 内部可读可写) */
@property (nonatomic , strong , readwrite) NSArray * accessoryButtons;
/** 标题按钮数组 */
@property (nonatomic , strong , readwrite) NSMutableArray * titleButtons;
/** 底部滑动下划线 */
@property (nonatomic , weak) CALayer * underLine;
/** 当前选中的按钮 */
@property (nonatomic , weak , readwrite) UIButton * selectedButton;
@end
@implementation TFScrollNavigationBar
#pragma mark - 初始化方法
/** 根据传进来的控制器数组进行初始化 , 实际目的只是为了获取控制器的标题 */
- (instancetype)initWithControllers : (NSArray *) controllers
{
self = [super init];
if (self)
{
/** 添加子控制器的标题 */
[self addTitlesFromChildViewControllers: controllers];
/** 默认初始选中按钮为第一个 */
if (self.titleButtons.cou
汽车之家代码片段
最新推荐文章于 2024-03-18 08:47:09 发布
这是一个自定义的导航栏框架,包含标题滚动视图、右侧辅助按钮等功能。提供初始化方法、添加标题按钮、设置字体颜色和大小、监听按钮选中等接口。
摘要由CSDN通过智能技术生成