汽车之家代码片段

//
//  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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值