新浪微博开发之十九(文本框工具栏)

//
//  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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值