以编程方式创建多个视图

时间:2015-06-04 10:23:41

标签: ios views

你好我想问一下如何以编程方式创建多个视图并在屏幕上显示它们,我已经尝试了这个但是有些东西丢失了。

<FileNamePattern>${logDirectory}/${logFileName}.%d{yyyy-MM-dd}.%i.html</FileNamePattern>

3 个答案:

答案 0 :(得分:2)

int x,y,paddingX,widthOfView,HeightOfView;

x= 0;
y=50;
paddingX = 10;
widthOfView = 100;
HeightOfView = 100;

for (int i=0; i<4; i++){
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, widthOfView, HeightOfView)];
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview: view];

    y+= widthOfView + paddingX;
}

以下准则可能会对您有所帮助。

答案 1 :(得分:0)

int x,y;
x= 0;
y=50;

for (int i=0; i<4; i++)
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, 300, 100)];

    view.backgroundColor = [UIColor redColor];
    view.layer.cornerRadius = 5.0f;
    [self.view addSubview: view];
    y+=140; //y for next view should be height of previous view and margin between view 
} 

答案 2 :(得分:0)

  int x,y;

  x= 0;
  y=50
   for (int i=0; i<4; i++)
   {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, 30, 30)];

    view.backgroundColor = [UIColor redColor];
     y+=40;

    [self.view addSubview: view];    
  }