gpt4 book ai didi

IOS 自定义键盘。如何在自定义键盘中设置特殊字符

转载 作者:可可西里 更新时间:2023-11-01 04:43:36 31 4
gpt4 key购买 nike

我正在为 iphone 6 和 6Plus 开发自定义键盘。我已经为 shift key active-inactive 或 123 和 abc key 开发了逻辑。但我也想显示自定义符号,如所示的苹果键盘。请检查图片。

enter image description here

目前我可以将大写字母改为小写字母,将 123 改为 abc,但我该如何设置这个特殊字符。注意:- 我在 github 上搜索了很多演示,但我无法在任何自定义键盘中看到特殊字符。

这是我对 uppercaseABC-123 按钮的逻辑。

-(void)UpparCase:(UIButton*)sender   // To make caps or small letter
{

sender.selected=!sender.selected;
if(sender.selected)
{
if(isPortrait)
{

[self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"upparActive.png"] forState:UIControlStateNormal];
}
else
{
[self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_selctd_land.png"] forState:UIControlStateNormal];

}

for(UIButton *key in self.ObjKeyLayout.ArryCharKey)
{


NSString *uppercaseString = [[key currentTitle] uppercaseString];

[key setTitle:uppercaseString forState:UIControlStateNormal];

[key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside];

}
}
else
{

if(isPortrait)
{

[self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"UpperCase.png"] forState:UIControlStateNormal];
}
else
{
[self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_land.png"] forState:UIControlStateNormal];

}
for(UIButton *key in self.ObjKeyLayout.ArryCharKey)
{


NSString *uppercaseString = [[key currentTitle] lowercaseString];

[key setTitle:uppercaseString forState:UIControlStateNormal];

[key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside];

}

}
}

- (IBAction)action123:(UIButton*)sender // To set 123 and ABC
{


sender.selected=!sender.selected;

if(sender.selected)
{

[self.ObjKeyLayout.btn123Key setTitle:@"ABC" forState:UIControlStateNormal];
int i=0;

for(UIButton *key in self.ObjKeyLayout.ArryCharKey)
{

[key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i",i,(int)self.ObjKeyLayout.ArryCharKey.count);
if(isPortrait)
{
NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i\nArraySpecialImageKey.Count-%i\n",i,(int)self.ObjKeyLayout.ArryCharKey.count,(int)arrspecialImageKey.count);
[key setBackgroundImage:[UIImage imageNamed:[arrspecialImageKey objectAtIndex:i]] forState:UIControlStateNormal];




}
else{

[key setBackgroundImage:[UIImage imageNamed:[arrSpecialIpad objectAtIndex:i]] forState:UIControlStateNormal];

}

[key setTitle:[NumKey objectAtIndex:i] forState:UIControlStateNormal];

[key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside];
i++;
}
}
else
{
[self.ObjKeyLayout.btn123Key setTitle:@"123" forState:UIControlStateNormal];
int i=0;
for(UIButton *key in self.ObjKeyLayout.ArryCharKey)
{


[key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];


if(isPortrait)
{
[key setBackgroundImage:[UIImage imageNamed:[arrKeyImages objectAtIndex:i]] forState:UIControlStateNormal];
}
else
{


[key setBackgroundImage:[UIImage imageNamed:[keyIpad objectAtIndex:i]] forState:UIControlStateNormal];
}
;

NSString *uppercaseString = [arrAlphabet objectAtIndex:i];

[key setTitle:uppercaseString forState:UIControlStateNormal];

[key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside];
i++;
// is123selected=NO;
}
}

}

最佳答案

你有两个数组,一个用于alphabetical,另一个用于numerical

NSArray *NumKey;

NSArray *arrAlphabet;

现在在 NumKey 中:

NumKey=[[NSArray alloc]initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"0", @"-", @"/", @":", @";", @"(", @")", @"$", @"&", @"@", @"\"", @".", @",", @"?", @"!",@"'",@"^", nil];

arrAlphabet:

 arrAlphabet = [[NSArray alloc]initWithObjects:@"Q", @"W", @"E", @"R", @"T", @"Y", @"U", @"I", @"O", @"P", @"A", @"S", @"D", @"F", @"G", @"H", @"J", @"K", @"L", @"Z", @"X", @"C", @"V", @"B",@"N",@"M", nil];

键盘 123ABC 中的 IBOutlet。

如下所示以编程方式添加事件。

[self.keybard.btnNumeric addTarget:self action:@selector(action123:) forControlEvents:UIControlEventTouchUpInside];

123更改为ABC或将ABC更改为123的方法

- (IBAction)action123:(UIButton*)sender
{

if([self.keybard.btnNumeric.titleLabel.text isEqualToString:@"123"])
{
[self.keybard.btnCapital setTitle:@"#+=" forState:UIControlStateNormal];

[self.keybard.btnNumeric setTitle:@"ABC" forState:UIControlStateNormal];
int i=0;
for(UIButton *key in self.keybard.keyArray)
{
key.layer.cornerRadius = 6.0;

[key setTitle:[NumKey objectAtIndex:i] forState:UIControlStateNormal];

[key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside];
i++;
}
}
else
{
[self.keybard.btnCapital setTitle:@"⬆️" forState:UIControlStateNormal];

[self.keybard.btnNumeric setTitle:@"123" forState:UIControlStateNormal];

int i=0;
for(UIButton *key in self.keybard.keyArray)
{

strFirstCap = @"0";

NSString *uppercaseString = [arrAlphabet objectAtIndex:i];

[key setTitle:[uppercaseString lowercaseString] forState:UIControlStateNormal];

[key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside];
i++;
}

}

}

输出:

enter image description here

关于IOS 自定义键盘。如何在自定义键盘中设置特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32048884/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com