如何在单击时使自定义按钮键像 iPhone 按钮键一样大
Posted
技术标签:
【中文标题】如何在单击时使自定义按钮键像 iPhone 按钮键一样大【英文标题】:How to make customized button key bigger like iPhone button key while clicking 【发布时间】:2012-09-03 07:53:34 【问题描述】:点击时,我想要这张图片中的大字母。
如何为我的新按钮“ក”执行此操作?这是我创建按钮的代码:
consonantButton = [UIButton buttonWithType:UIButtonTypeCustom];
[consonantButton setTitle:@"ក" forState:UIControlStateNormal];
consonantButton.titleLabel.font = [UIFont fontWithName:@"Hanuman" size:30];
consonantButton.frame = CGRectMake(242.0, 328.0, 27.0, 42.0);
[consonantButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[consonantButton setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
// [consonantButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
// [consonantButton setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
// consonantButton.titleLabel.shadowOffset = CGSizeMake(0, -1);
[consonantButton setBackgroundImage:[UIImage imageNamed:@"doneButtonNormal-khmer"] forState:UIControlStateNormal];
// [consonantButton setBackgroundImage:[UIImage imageNamed:@"doneButtonHighlighted-khmer"] forState:UIControlStateHighlighted];
[consonantButton addTarget:self action:@selector(touchConsonantButton:) forControlEvents:UIControlEventTouchUpInside];
如何在点击时做出这样的形状?这叫什么 ? 这是我为行动所做的代码: - (void) touchConsonantButton:(UIButton*)sender // [self.target performSelector:consonantAction withObject:sender]; consonantButton.frame = CGRectMake(242.0, 310.0, 54.0, 84.0); consonantButton.titleLabel.font = [UIFont fontWithName:@"Hanuman" size:50];
这是屏幕截图:(默认不会消失)
【问题讨论】:
这封信最后是怎么写的?我记得我昨天回答了你的一个问题。 在我还没加代码和图片之前,所以我再问1个时间来弄清楚s.o是否有答案!我还要求你给我一些代码,所以我再问1次!对不起,我不编辑旧的并制作新的! 这是我单击按钮时所做的代码: - (void) touchConsonantButton:(UIButton*)sender // [self.target performSelector:consonantAction withObject:sender]; consonantButton.frame = CGRectMake(242.0, 310.0, 54.0, 84.0); consonantButton.titleLabel.font = [UIFont fontWithName:@"Hanuman" size:50]; if (onSetTextFieldCallBack!= nil) NSMutableString *c = (NSMutableString *)[[(UIButton *)sender titleLabel] text]; self.onSetTextFieldCallBack (c); 【参考方案1】:为您的按钮添加两个目标:
[consonantButton addTarget:self action:@selector(touchUpConsonantButton:) forControlEvents:UIControlEventTouchUpInside];
[consonantButton addTarget:self action:@selector(touchDownConsonantButton:) forControlEvents:UIControlEventTouchDownInside];
现在选择器是:
-(void)touchUpConsonantButton(id)sender
UIButton *btnClicked = (UIButton *)sender;
// your code here
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^
btnClicked.transform = CGAffineTransformMakeScale(2.0f, 2.0f);
completion:^(BOOL finished)
// if you want to do something once the animation finishes, put it here
];
-(void)touchDownConsonantButton(id)sender
UIButton *btnDown = (UIButton *)sender;
// your code here
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^
btnDown.transform = CGAffineTransformIdentity;
completion:^(BOOL finished)
// if you want to do something once the animation finishes, put it here
];
【讨论】:
以上是关于如何在单击时使自定义按钮键像 iPhone 按钮键一样大的主要内容,如果未能解决你的问题,请参考以下文章