简体   繁体   English

在iPhone上更改背景图像的按钮

[英]Buttons changing background images on iPhone

I have it working with a small error. 我有一个小错误。 I have two code pieces for each button. 每个按钮都有两个代码段。 One being this: 一个是这样的:

-(IBAction)clickoneButton:(id)sender
{
    [sender setBackgroundImage:[UIImage imageNamed:@"cnumber_1.jpg"] forState:UIControlStateNormal];
}

And the other being this: 另一个是这样的:

-(IBAction)oneButton:(id)sender
{
    self.enteredPhoneNumberString = [self.enteredPhoneNumberString stringByAppendingString:[NSString stringWithFormat:@"%d", 1]];
    [self updateFormattedPhoneNumberLabel];

    [sender setBackgroundImage:[UIImage imageNamed:@"Number_1.jpg"] forState:UIControlStateNormal];
}

The first is set up to be Touch Down. 第一个设置为Touch Down。 The other is for Touch Up Inside. 另一个用于“ Touch Up Inside”。 The app looks like the phones regular dialer. 该应用看起来像手机的常规拨号器。 So the first image is a light blue button and the second is a dark blue button just the same way as the iPhones dialer is. 因此,第一个图像是一个浅蓝色按钮,第二个图像是一个深蓝色按钮,与iPhone的拨号器相同。 The issue is when I press down on the button it almost seems like the dark image is still behind the Touch Down light blue image. 问题是当我按下按钮时,深色图像似乎似乎仍在Touch Down浅蓝色图像后面。 It is changing to a lighter colored image but is shaded almost like the dark image is transparent through it or something. 它正在变为浅色图像,但阴影几乎像深色图像一样通过它或其他东西透明。 Not sure how else to explain it. 不知道该如何解释。 If you have any ideas as to why the light blue is darkened some when the Touch Down is happening I would appreciate any help. 如果您对为何在Touch Down发生时为什么浅蓝色会变暗有任何想法,我们将不胜感激。 Thanks 谢谢

触摸前和释放后的按钮 Button before touch and after release (Correct) 触摸前和释放后的按钮(正确)

按下按钮 Button on Touch Down (not working properly) 触屏按钮(无法正常工作)

“ Touch Down”按钮应该是什么样的 What the touch down button should look like 触地按钮应该是什么样子

Based upon the two snippets of code you provided, you are not setting an image for when the button is pressed. 根据您提供的两个代码段,您没有为按下按钮时设置图像。 Try updating your code to use the following when you load the view: 加载视图时,请尝试更新代码以使用以下代码:

// sets the background image for when the button is not pressed
[sender setBackgroundImage:[UIImage imageNamed:@"cnumber_1.jpg"] forState:UIControlStateNormal];

// sets the background image for when the button is pressed
[sender setBackgroundImage:[UIImage imageNamed:@"Number_1.jpg"] forState:UIControlStateHighlighted];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM