如何使用两个UIview
来保留UIbutton
,其中用户可以将参数传递给自定义类
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
CanvasView *newCanvas = [[CanvasView alloc] initWithFrame:CGRectMake(0.0, 164.0, self.view.frame.size.width, self.view.frame.size.height-350)];
self.canvas = newCanvas;
[self.view addSubview:canvas];
}
我只能自定义UIView
!如何将两个UIButton
添加到View。
当我分配UIView
自定义类时,它也需要显示UIButtons
答案 0 :(得分:1)
您可以使用以下代码
创建动态按钮CanvasView *newCanvas = [[CanvasView alloc] initWithFrame:CGRectMake(0.0, 164.0, self.view.frame.size.width, self.view.frame.size.height-350)];
self.canvas = newCanvas;
[self.view addSubview:newCanvas];
UIButton *but=[UIButton buttonWithType:UIButtonTypeRoundedRect];
but.frame= CGRectMake(200, 15, 15, 15);
[but setTitle:@"Ok" forState:UIControlStateNormal];
[but addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[newCanvas addSubview:but];
您可以使用insertSubview:atIndex方法
[newCanvas insertSubview:myButton atIndex:0];
希望它对你有所帮助。