[英]UIButton animation view
I am new developer in iPhone. 我是iPhone的新开发人员。
I want to create uibutton. 我想创建uibutton。
When I click the button, then the button will be flash like as below. 当我单击按钮时,按钮将闪烁,如下所示。
How to create the flash, when I click my button? 单击按钮时如何创建闪光灯?
There is a property of UIButton named showsTouchWhenHighlighted . UIButton有一个名为showsTouchWhenHighlighted的属性。 If you set the property to YES, it will show the glow when you touch the button. 如果将该属性设置为YES,则当您触摸按钮时它将显示发光。 It's default value is NO. 默认值为“否”。
[yourButton setShowsTouchWhenHighlighted:YES]; [yourButton setShowsTouchWhenHighlighted:YES];
What you do is set the highlighted image. 您要做的是设置突出显示的图像。 For example: 例如:
[someButton setImage:[UIImage imageNamed:@"MyHighlight.png"]
forState:UIControlStateHighlighted];
Then when a user taps it, your MyHighlight.png
will show. 然后,当用户点击它时,将显示MyHighlight.png
。
toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleDefault;
[toolbar sizeToFit];
toolbar.frame = CGRectMake(0, 410, 320, 50);
//Add buttons
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pressButton1:)];
UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(pressButton2:)];
UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self action:@selector(pressButton3:)];
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];
//release buttons
[systemItem1 release];
[systemItem2 release];
[systemItem3 release];
[flexItem release];
//add array of buttons to toolbar
[toolbar setItems:items animated:NO];
[self.view addSubview:toolbar];
use this to create toolBar. 使用它来创建工具栏。
and use this for search button 并将其用作搜索按钮
UIBarButtonSystemItemSearch
If you want to change the button image when you clicked on button now set different images for both default and highlighted stats. 现在,如果您想在单击按钮时更改按钮图像,请为默认统计信息和突出显示的统计信息设置不同的图像。 As: 如:
[tempButton setImage:[UIImage imageNamed:@"NormalImage.png"]
forState:UIControlStateNormal];
[tempButton setImage:[UIImage imageNamed:@"HighlightImage.png"]
forState:UIControlStateHighlighted];
If you want the flash effect for the same image, when button is clicked on, In your XIB, Goto Inspector window > control > check the Highlighted property. 如果希望同一图像具有闪光效果,请在单击按钮时,在XIB中的“转到检查器”窗口>“控件”中,选中“突出显示”属性。 You can try this by code as: 您可以通过以下代码尝试此操作:
[tempButton setShowsTouchWhenHighlighted:YES];
//or
tempButton.highlighted = YES;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.