// MyTextToolBar.h
// 新浪微博
//
// Created by jose on 15-3-27.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import <UIKit/UIKit.h>
@class MyTextToolBar;
typedef enum{
MyCamera, //相机
MyPicture, //相册
MyMention, //提到@
MyTrend, //话题
MyEmotion, //表情
}MyTextToolButton;
//代理
@protocol MyTextToolBarDelegate<NSObject>
-(void)MyToolBarClick:(MyTextToolBar *)toolbar Click:(MyTextToolButton)tag;
@end
@interface MyTextToolBar : UIView
@property(nonatomic,weak)id<MyTextToolBarDelegate>delegate;
@end
***********************************************************************************************************************
***********************************************************************************************************************
***********************************************************************************************************************
//
// MyTextToolBar.m
// 新浪微博
//
// Created by jose on 15-3-27.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import "MyTextToolBar.h"
#import "UIView+Extension.h"
@implementation MyTextToolBar
//初始化控件布局
-(id)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if(self){
[self AddButtonWithIcon:@"compose_trendbutton_background@2x" HighIcon:@"compose_trendbutton_background_highlighted@2x" Tag:MyTrend];
[self AddButtonWithIcon:@"compose_camerabutton_background_unuse@2x" HighIcon:@"compose_camerabutton_background_highlighted@2x" Tag:MyCamera];
[self AddButtonWithIcon:@"compose_toolbar_picture@2x" HighIcon:@"compose_toolbar_picture_highlighted@2x" Tag:MyPicture];
[self AddButtonWithIcon:@"compose_mentionbutton_background@2x" HighIcon:@"compose_mentionbutton_background_highlighted@2x" Tag:MyMention];
[self AddButtonWithIcon:@"compose_emoticonbutton_background@2x" HighIcon:@"compose_emoticonbutton_background_highlighted@2x" Tag:MyEmotion];
}
return self;
}
/**
* 文本工具栏
*
* @param icon 普通
* @param highicon 高亮
* @param tag 按钮tag
*/
-(void)AddButtonWithIcon:(NSString *)icon HighIcon:(NSString *)highicon Tag:(MyTextToolButton)tag{
UIButton *button=[[UIButton alloc]init];
button.tag=tag;
[button setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:highicon] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
-(void)button:(UIButton *)button{
if ([self.delegate respondsToSelector:@selector(MyToolBarClick:Click:)]) {
[self.delegate MyToolBarClick:self Click:button.tag];
}
}
//重写方法布局子控件
-(void)layoutSubviews{
[super layoutSubviews];
//获取当前子控件的数
NSInteger count=self.subviews.count;
CGFloat btnw=self.width/count;
CGFloat btnh=self.height;
for (int i=0; i<count; i++) {
UIButton *button=self.subviews[i];
button.y=0;
button.width=btnw;
button.height=btnh;
button.x=i*btnw;
}
}
@end