我有子视图,它通过触摸主视图中的UIbutton触发。 一旦子视图弹出,它就会显示带有我提供的信息的标签。这一切都有效。我只需要一个UIbutton来显示,这样我就可以设置它来关闭子视图并返回到主视图。我搜遍了,并没有发现任何有用的东西。添加自定义UIButton到子视图
这里是我在我的.m文件的代码如下所示:
////Button that Displays Subview with Its Label and Button
- (IBAction)showInfo:(id)sender
/////UI Subview
{UIView *mySubview = [[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 480)];
[self.view addSubview:mySubview];
mySubview.backgroundColor = [UIColor blackColor];
mySubview.alpha = .7f;
//////Label in SubView
{UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 50)];
label.text = @"Here is info";
label.textColor = [UIColor whiteColor];
label.backgroundColor= [UIColor clearColor];
[self.view addSubview:label];
////Button in Subview
//create the button
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"button-info-x.png"] forState:UIControlStateNormal];
//set the position of the button
button.frame = CGRectMake(120, 252, 68, 68);
//add the button to the view
[self.view addSubview:button];
现在我只需要一个操作添加到UIButton的驳回子视图?
我编辑了我的代码,并将其放在我的文章中。请看看,然后告诉我如何为按钮做出动作。我有点迷路 – Gabriel 2012-03-20 06:47:34