自定义键盘工具条

#import <UIKit/UIKit.h>

typedef enum {
    HMComposeToolbarButtonTypeCamera, // 照相机
    HMComposeToolbarButtonTypePicture, // 相册
    HMComposeToolbarButtonTypeMention, // 提到@
    HMComposeToolbarButtonTypeTrend, // 话题
    HMComposeToolbarButtonTypeEmotion // 表情
} HMComposeToolbarButtonTypes;

@class HMComposeToolbar;

@protocol HMComposeToolbarDelegate <NSObject>

@optional
- (void)composeTool:(HMComposeToolbar *)toolbar didClickedButton:(HMComposeToolbarButtonTypes)buttonType;

@end

@interface HMComposeToolbar : UIView
@property (nonatomic, weak) id<HMComposeToolbarDelegate> delegate;
/**
 *  设置某个按钮的图片
 *
 *  @param image      图片名
 *  @param buttonType 按钮类型
 */
//- (void)setButtonImage:(NSString *)image buttonType:(HMComposeToolbarButtonType)buttonType;

/**
 *  是否要显示表情按钮
 */
@property (nonatomic, assign, getter = isShowEmotionButton) BOOL showEmotionButton;
@end
#import "HMComposeToolbar.h"
#import "UIImage+Extension.h"
#import "UIView+WLFrame.h"
#import "UIView+Extension.h"
@interface HMComposeToolbar()
@property (nonatomic, weak) UIButton *emotionButton;
@end

@implementation HMComposeToolbar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithName:@"compose_toolbar_background"]];

        // 添加所有的子控件
        [self addButtonWithIcon:@"compose_camerabutton_background" highIcon:@"compose_camerabutton_background_highlighted" tag:HMComposeToolbarButtonTypeCamera];
        [self addButtonWithIcon:@"compose_toolbar_picture" highIcon:@"compose_toolbar_picture_highlighted" tag:HMComposeToolbarButtonTypePicture];
        [self addButtonWithIcon:@"compose_mentionbutton_background" highIcon:@"compose_mentionbutton_background_highlighted" tag:HMComposeToolbarButtonTypeMention];
        [self addButtonWithIcon:@"compose_trendbutton_background" highIcon:@"compose_trendbutton_background_highlighted" tag:HMComposeToolbarButtonTypeTrend];
        self.emotionButton = [self addButtonWithIcon:@"compose_emoticonbutton_background" highIcon:@"compose_emoticonbutton_background_highlighted" tag:HMComposeToolbarButtonTypeEmotion];
    }
    return self;
}

/**
    键盘切换
 */
- (void)setShowEmotionButton:(BOOL)showEmotionButton
{
    _showEmotionButton = showEmotionButton;
    if (showEmotionButton) { // 显示表情按钮
        [self.emotionButton setImage:[UIImage imageWithName:@"compose_emoticonbutton_background"] forState:UIControlStateNormal];
        [self.emotionButton setImage:[UIImage imageWithName:@"compose_emoticonbutton_background_highlighted"] forState:UIControlStateHighlighted];
    } else { // 切换为键盘按钮
        [self.emotionButton setImage:[UIImage imageWithName:@"compose_keyboardbutton_background"] forState:UIControlStateNormal];
        [self.emotionButton setImage:[UIImage imageWithName:@"compose_keyboardbutton_background_highlighted"] forState:UIControlStateHighlighted];
    }
}

/**
 *  添加一个按钮
 *
 *  @param icon     默认图标
 *  @param highIcon 高亮图标
 */
- (UIButton *)addButtonWithIcon:(NSString *)icon highIcon:(NSString *)highIcon tag:(HMComposeToolbarButtonTypes)tag
{
    UIButton *button = [[UIButton alloc] init];
    button.tag = tag;
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageWithName:icon] forState:UIControlStateNormal];
    [button setImage:[UIImage imageWithName:highIcon] forState:UIControlStateHighlighted];
    [self addSubview:button];
    return button;
}

/**
 *  监听按钮点击
 */
- (void)buttonClick:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(composeTool:didClickedButton:)]) {
        [self.delegate composeTool:self didClickedButton:button.tag];
    }
}

// 设置按钮frame
- (void)layoutSubviews
{
    [super layoutSubviews];

    int count = self.subviews.count;
    CGFloat buttonW = self.width / count;
    CGFloat buttonH = self.height;
    for (int i = 0; i<count; i++) {
        UIButton *button = self.subviews[i];
        button.y = 0;
        button.width = buttonW;
        button.height = buttonH;
        button.x = i * buttonW;
    }
}

@end

在控制器中

- (void)addToolBar {
    HMComposeToolbar *toolbar = [[HMComposeToolbar alloc]init];
    toolbar.width = self.view.width;
    toolbar.height = 44;
    toolbar.y = self.view.height - toolbar.height;
    toolbar.delegate = self;
    [self.view addSubview:toolbar];
    self.toolbar = toolbar;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Unity科技空间线条背景Demo是一个具有创意和未来感的技术演示,它是由Unity引擎开发的一款游戏/应用程序演示。这个演示的主要特点是使用了动态的线条背景,它能够营造一种未来感和科技感。用户可以通过旋转和缩放屏幕来改变背景的效果。在演示中,我们可以看到各种几何图形和抽象的线条,这些形状会随着用户交互而随机生成和演变。除此之外,演示中还有一些物理效果和粒子效果,使整个场景更加生动和有趣。 Unity科技空间线条背景Demo不仅是一款有创意和吸引人的科技演示,也是一种技术实现方式的展示。它展示了如何使用Unity引擎的2D和3D渲染技术,以及动画和物理引擎的效果。在开发过程中,开发者们需要使用Unity编辑器和C#脚本语言来编写代码和设计游戏场景。这些技术对于游戏和应用程序的开发都非常重要,因为它们可以使开发人员更轻松地实现想法,并提供更好的用户体验。 总的来说,Unity科技空间线条背景Demo是一款兼具兴趣和技术的科技演示程序,它能够吸引和激发用户的好奇心,同时也展示了一些现代网络技术的基础知识。无论是在开发科技演示还是游戏应用程序时,这些技术都对开发者有很大的作用。 ### 回答2: Unity科技空间线条背景demo是一款非常炫酷的背景效果展示工具。它的核心技术是基于Unity3D游戏引擎开发的。该demo通过利用Unity引擎的粒子系统特效、音效、动态光影等多种技术,创造出一种充满科技感和未来感的虚拟空间。 在这个Unity科技空间线条背景demo中,我们可以看到大量的五彩缤纷的线条,在黑暗的背景中飞舞着,好似宇宙空间中的星河图案。而这些光线的运动、颜色、形状等都可以通过Unity引擎的参数来进行调节,用户可以根据自己的需求进行自定义设置,生成独一无二的线条背景效果。 除了酷炫的线条效果之外,这个Unity科技空间线条背景demo还具有强大的交互性。用户可以通过键盘、鼠标等设备来操控场景中的效果,比如进行旋转、放大、缩小、切换等操作。同时,在这个虚拟空间中,还会配以震撼的音效,给用户带来一种身临其境的感觉。 总的来说,这个Unity科技空间线条背景demo是一款非常棒的展示工具,不仅可以为用户带来炫酷的视觉效果,还具有强大的交互性和个性化定制功能,能够满足各种不同需求的用户使用。 ### 回答3: Unity科技空间线条背景demo是一个基于Unity引擎开发的演示项目,可以展示三维空间中的线条背景效果。该demo主要使用了Unity引擎中的Shader编程技术和粒子系统等功能。 该demo的场景设置在一个宇宙空间中,其中包括了一个璀璨的星空和一些随机生成的星球。在这个场景中,用户可以看到一些具有流动感的线条背景,这些线条不仅可以作为一种注目的视觉效果,同时也可以配合场景中的星球运动和星空背景,使整个场景更加生动。 这个demo的实现过程中,Shader编程起到了很重要的作用。通过调整Shader中参数的值,可以实现线条背景的颜色、密度和流动速度等的调节。同时,该项目还运用了粒子系统使得整个场景更具有动态感。 总的来说,Unity科技空间线条背景demo是一个优秀的演示项目,可以用来展示Unity引擎的应用和Shader编程技术的应用。同时,它也可以为游戏开发者提供一些有趣的灵感和想法。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值