iOS开发系列之常用自定义控件开发集—自定义组按钮控件开发

在开发中经常有需求要求创建一排按钮,下面我们就开发这一个组件,实现方式如下:
WHC_ButtonGroupView.h头文件如下:

//
//  buttonGroupView.h
//  buttonGroupView
//
//  Created by 吴海超 on 14-6-6.
//  Copyright (c) 2014年 buttonGroupView. All rights reserved.
//


/*
 NOTE:获取组按钮默认创建实现方式如下:
 +(WHC_ButtonGroupParam *)getDefaultParamWithTitleArr:(NSArray*)titleArr{
     WHC_ButtonGroupParam * groupParam = [WHC_ButtonGroupParam new];
     groupParam.normalBackColor      = [UIColor grayColor];
     groupParam.selectedBackColor    = [UIColor blackColor];
     groupParam.markColor            = [UIColor clearColor];
     groupParam.segmentLineY         = 0.0;
     groupParam.segmentLineColor     = [UIColor blackColor];
     groupParam.normalTextColor      = [UIColor whiteColor];
     groupParam.selectedTextColor    = [UIColor grayColor];
     groupParam.titles               = titleArr;
     groupParam.images               = nil;
     groupParam.scroll               = NO;
     groupParam.headLine             = YES;
     groupParam.footLine             = YES;
     groupParam.firstSegmentLine     = YES;
     groupParam.markViewDown         = NO;
     groupParam.fontSize             = 16.0;
     groupParam.markPading           = 5.0;
     return groupParam;
 }

 */

#import <UIKit/UIKit.h>
@class WHC_ButtonGroupView;
@protocol  WHC_ButtonGroupViewDelegate<NSObject>

@required
- (void)whcButtonGroup:(WHC_ButtonGroupView*)whcBtnView index:(NSInteger)index;
@end

@interface WHC_ButtonGroupParam : NSObject
@property BOOL    scroll;                      //是否支持滚动
@property BOOL    footLine;                    //是否显示底部线
@property BOOL    headLine;                    //是否显示顶部线
@property BOOL    markViewDown;                //是否下标记
@property BOOL    firstSegmentLine;            //首部分割线
@property int     currIndex;                   //当前下标
@property CGFloat fontSize;                    //字体大小
@property CGFloat btnHeight;                   //按钮高度
@property CGFloat btnWidth;                    //按钮宽度
@property CGFloat markPading;                  //游标和按钮的间隙
@property CGFloat segmentLineY;                //分隔线Y坐标
@property CGFloat scrollWidth;                 //滚条宽度
@property UIColor *normalBackColor;            //默认按钮背景颜色
@property UIColor *selectedBackColor;          //选中按钮背景颜色
@property UIColor *normalTextColor;            //默认状态按钮文字颜色
@property UIColor *selectedTextColor;          //选中状态按钮文字颜色
@property UIColor *segmentLineColor;           //分隔线颜色
@property UIColor *markColor;                  //移动游标颜色
@property NSArray *titles;                     //按钮标题
@property NSArray *images;                     //按钮图片

+ (WHC_ButtonGroupParam *)getDefaultParamWithTitleArr:(NSArray*)titleArr;      //获取默认参数
@end

@interface WHC_ButtonGroupView : UIView
@property id<WHC_ButtonGroupViewDelegate> delegate;
- (void)changeSelectedStateButtonWithIndex:(NSInteger)index;                   //改变指定按钮的状态

- (BOOL)deleteButtonWithIndex:(NSInteger)index withTitle:(NSString*)title;     //删除指定按钮

- (BOOL)addButtonWithIndex:(NSInteger)index withTitle:(NSString*)title;        //添加按钮到指定位子

- (void)switchUIOrientationWithIsHori:(BOOL)isHori withPading:(CGFloat)pad;    //转换屏幕处理

- (id)initWithFrame:(CGRect)frame withParam:(WHC_ButtonGroupParam*)param;     //初始化

- (void)gotoOtherBtnOptionWithIndex:(NSInteger)index;                          //切换到其他按钮响应

- (void)modifyButtonTitleForIndex:(NSInteger)index withTitle:(NSString*)title; //修改指定按钮标题
@end

WHC_ButtonGroupView.m源文件如下:

//
//  buttonGroupView.m
//  bhtrader
//
//  Created by apple on 14-6-6.
//  Copyright (c) 2014年 InvestGu. All rights reserved.
//

#import "WHC_ButtonGroupView.h"
#define kLineWidth (1.0)
#define KANMATION_TIME 0.2
@implementation WHC_ButtonGroupParam
//返回默认样式
+(WHC_ButtonGroupParam *)getDefaultParamWithTitleArr:(NSArray*)titleArr{
    WHC_ButtonGroupParam * groupParam = [WHC_ButtonGroupParam new];
    groupParam.normalBackColor      = [UIColor grayColor];
    groupParam
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值