【问题标题】:How to use custom emoji view from iPhone default keyboard?如何从 iPhone 默认键盘使用自定义表情符号视图?
【发布时间】:2013-08-12 06:04:38
【问题描述】:

我正在开发一个 iPhone 应用程序,该应用程序允许用户绘制表情符号并在带有文本的 cmets 时使用它(例如 iPhone 允许用户通过从设置中启用表情符号键盘来使用他们的表情符号)。我想使用我自己制作的表情符号。我将所有表情符号存储在集合视图中。如何从 iPhone 默认键盘启用该视图,以便我可以使用我自己的自定义表情符号和文本?

【问题讨论】:

  • 您是否在询问是否要像使用默认键盘一样创建自定义键盘
  • 是的,请帮帮我,给我指路。

标签: iphone keyboard emoji


【解决方案1】:

在您的应用程序中使用自定义键盘时,只需使用 UITextField 的 inputView 属性。 您可以通过以下方式执行此操作:

@interface SCAViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property ( nonatomic) UIView *labelView;

@end

@implementation SCAViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// here we set the keyboard to become the first responder
// this is optional...
//[_textField becomeFirstResponder];

// creating the custom label keyboard
_labelView = [[UIView alloc] initWithFrame:CGRectMake(0, 568, 320, 568/3)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
label.text = @"Label View!";
[_labelView addSubview:label];
_labelView.backgroundColor = [UIColor blueColor];
_textField.inputView = _labelView;
}

现在解释一下:

_labelView 设置为当前尺寸的原因是因为我想要与默认键盘紧密匹配。您可以随时将它们更改为您需要的任何内容。 我在视图中添加了一个标签,但是由于您正在使用表情符号,因此我将创建一个方法,该方法将使用按钮将图像加载到 textField 中。

列表如下:

  • 为按钮创建操作方法
  • 创建按钮
  • 设置按钮的背景图片
  • 在自定义视图上添加按钮
  • 将 inputView 设置为自定义视图

你可以像这样创建动作方法

// create the method for the button
 - (IBAction) loadOntoKeyboard {
    // load the image/text/whatever else  into the textfield
 }

您可以创建一个按钮以添加到您的自定义视图中,例如

 // creating custom button
 UIButton *emoji1 = [UIButton buttonWithType:UIButtonTypeCustom];

 // creating frame for button. 
 // x - the location of the button in x coordinate plane
 // y - same as x, but on y plane
 // width - width of button
 // height - height of button
 emoji1.frame = CGRectMake(x, y, width, height);

 // just setting background image here
 [emoji1 setBackgroundImage:[UIImage imageNamed:@"emoji_image…"] forState:UIControlStateNormal];

 // don't forget to add target of button
 [emoji1 addTarget:self action:@selector(loadOntoKeyboard) forControlEvents:UIControlEventTouchUpInside];

 // adding button onto view
 [customView addSubview:emoji1];

 // setting the inputView to the custom view where you added the buttons
 textFieldVariable.inputView = customView;

希望这一切对你有意义,我希望我能帮助你清楚地了解如何实现自定义键盘操作 :)

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2016-06-08
    • 2017-09-11
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    相关资源
    最近更新 更多