I am new developer in iPhone.
I want开发者_运维百科 to create 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. If you set the property to YES, it will show the glow when you touch the button. It's default value is NO.
[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.
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. You can try this by code as:
[tempButton setShowsTouchWhenHighlighted:YES];
//or
tempButton.highlighted = YES;
精彩评论