开发者

Anchor a function to UIButton programmatically

How can I anchor a function to my Button which I created this way

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开发者_Go百科, 160.0, 40.0);

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

I want to do similar as it do IB when I link a function to a button. Is it possible?


You're doing it right (assuming your aMethod gets 1 parameter - the ui control that triggers event). The only difference from action wired by default in IB - is that in IB action is set for UIControlEventTouchUpInside event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜