2012-07-10 69 views

回答

0

在.xib文件中添加一个UIButton并给出一些名称。

在代码中添加下列方法。 - (IBAction)bubbleButn:(UIButton *)btn

然后右键单击该按钮并在菜单中看到“Touch Up Inside”部分。然后,您可以在Xocde的“占位符”部分中单击并将最右侧的圆圈拖动到文件所有者。然后你可以看到方法名称出现在菜单中。您可以从那里选择我们的方法。

接下来我们要实现我们的代码。

首先,您必须在.h文件中声明一个UILabel。

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController { 
    UILabel *bubbleLabel_; 
} 

@end 

然后在.m文件中执行按钮操作和标签设置。

- (IBAction)bubbleButn:(UIButton *)btn { 
    float half = btn.frame.size.width/2; 
    float yVal = btn.frame.size.height/2; 
    if(bubbleLabel_) { 
    /* 
    If you are using 'arc' no need of this statement 
    add this in the dealloc method also. 
    */ 
    [bubbleLabel_ release]; 
    bubbleLabel_ = nil; 
} 
    bubbleLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(btn.frame.origin.x+half, btn.frame.origin.y+yVal, 40, 50)];       
    bubbleLabel_.text = @"Hi"; 

    [self.view addSubview:bubbleLabel_]; 

    [self performSelector:@selector(hideBubble) withObject:self afterDelay:3]; 

} 


- (void) hideBubble { 
    [bubbleLabel_ removeFromSuperview]; 
} 

命名标签“嗨”将在那里为3秒。

去吧...

+0

感谢这一点,但是,我需要泡是半路按钮外面太..喜欢上的按钮语音泡... – inforeqd 2012-07-10 05:23:52

+0

您可以修改框架的设置UILabel并调整按钮旁边的框架。 – 2012-07-10 05:39:08