Relativelayout or LinearLayout in ios iphone development?

前端 未结 6 655
再見小時候
再見小時候 2021-02-08 15:23

I want to add a subview in the top of my view, I have to recalculate the origin y value for all of other views and re-position them to leave space for the new added view.

<
6条回答
  •  [愿得一人]
    2021-02-08 15:44

    I've created a library to solve just this problem: CSLinearLayoutView

    You use it like this:

    // create the linear layout view
    CSLinearLayoutView *linearLayoutView = [[[CSLinearLayoutView alloc] initWithFrame:self.view.bounds] autorelease];
    linearLayoutView.orientation = CSLinearLayoutViewOrientationVertical;
    [self.view addSubview:linearLayoutView];
    
    // create a layout item for the view you want to display and add it to the layout view
    CSLinearLayoutItem *item = [CSLinearLayoutItem layoutItemForView:someView];
    item.padding = CSLinearLayoutMakePadding(5.0, 10.0, 5.0, 10.0);
    item.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentCenter;
    item.fillMode = CSLinearLayoutItemFillModeNormal;
    [linearLayoutView addItem:item];
    
    // add more items
    

提交回复
热议问题