[英]How to customize a UIview with two UIbutton
How to custmoize a UIview
with two UIbutton
where user can pass parameter to the customize class 如何custmoize一个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];
}
I can only customize the UIView
! 我只能自定义UIView
! how to add the two UIButton
to View. 如何将两个UIButton
添加到View。
When I allocate the UIView
Custom Class it need to visible UIButtons
too 当我分配UIView
自定义类时,它也需要可见的UIButtons
You can create dynamic buttons using the following code 您可以使用以下代码创建动态按钮
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];
You can either use the insertSubview:atIndex method 您可以使用insertSubview:atIndex方法
[newCanvas insertSubview:myButton atIndex:0];
Hope it helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.