2010-12-21 152 views
-1

我是iPhone的新开发者。UIButton动画视图

我想创建uibutton。

当我点击按钮,那么按钮将闪烁如下。

alt text

如何创建闪光灯,当我点击我的按钮?

回答

2

还有的UIButton的属性命名showsTouchWhenHighlighted: 您可以通过代码试试这个。如果您将该属性设置为YES,则当您触摸该按钮时,它会显示发光。它的默认值是NO。

[yourButton setShowsTouchWhenHighlighted:YES];

0

你要做的是设置突出显示的图像。例如:

[someButton setImage:[UIImage imageNamed:@"MyHighlight.png"] 
      forState:UIControlStateHighlighted]; 

然后当用户点击它时,您的MyHighlight.png将显示。

0
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]; 

用这个来创建toolBar。

,如果你想更改按钮图像,当你点击按钮,现在设置不同的图像,两者的默认,并强调统计用这个搜索按钮

UIBarButtonSystemItemSearch 
0

。正如:

[tempButton setImage:[UIImage imageNamed:@"NormalImage.png"] 
      forState:UIControlStateNormal]; 
[tempButton setImage:[UIImage imageNamed:@"HighlightImage.png"] 
      forState:UIControlStateHighlighted]; 

如果你想在同一图像的闪光效果,被点击按钮时, 在你的厦门国际银行,转到Inspector窗口>控制>检查突出显示的属性。

[tempButton setShowsTouchWhenHighlighted:YES]; 

//or 
tempButton.highlighted = YES;