2012-06-18 69 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]; 

希望它可以幫助你。

相關問題