2011-01-14 23 views
3

我怎麼能錨的功能,我的按鈕,我創造了這樣錨UIButton的函數編程

button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
button.titleLabel.font   = [UIFont systemFontOfSize: 12]; 
button.titleLabel.lineBreakMode = UILineBreakModeTailTruncation; 
button.titleLabel.shadowOffset = CGSizeMake (1.0, 0.0); 
[button addTarget:self      
       action:@selector(aMethod:) 
    forControlEvents:UIControlEventTouchDown]; 

button.frame = CGRectMake(80.0, 160.0, 160.0, 40.0); 

[button setTitle:string forState:UIControlStateNormal]; 
[self.view addSubview:button]; 

我想這樣做similliar因爲它做IB,當我鏈接功能的按鈕。 這可能嗎? 感謝您的幫助

回答

4

你做得很對(假設你的aMethod得到1個參數 - 觸發事件的ui控件)。與IB中缺省連線動作的唯一區別 - 在IB動作中設置爲UIControlEventTouchUpInside事件。

+0

非常感謝它所做的一切 – Csabi 2011-01-14 13:13:23