2012-06-18 37 views
0

如何custmoize一两个UIbuttonUIview,其中用户可以通过参数自定义类如何自定义一个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

不知道你是什么意思''我只能自定义UIView' – samfisher

+0

@samfisher!我正在自定义UIView,其中我的UIview在UIview上有两个按钮的添加!当我分配UIview,自定义类我需要出现两个按钮,我可以发送框架,我需要该按钮,自定义类! – kiran

+0

自定义视图是否已经有两个按钮? – dianz

回答

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]; 

希望它可以帮助你。

相关问题