簡體   English   中英

如何使用兩個UIbutton自定義UIview

[英]How to customize a UIview with two UIbutton

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

}

我只能自定義UIView 如何將兩個UIButton添加到View。

當我分配UIView自定義類時,它也需要可見的UIButtons

您可以使用以下代碼創建動態按鈕

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

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM