Implementing auto layout for views generated programmatically

后端 未结 2 374
别跟我提以往
别跟我提以往 2020-12-04 20:48

I have an app whose views are generated programmatically. Example:

-(void)loadView
{
    [super loadView];

// SET TOP LEFT BTN FOR NEXT VIEW
UIBarButtonItem         


        
2条回答
  •  被撕碎了的回忆
    2020-12-04 21:20

    In addition to Aplle provided methods you can use Parus lib for operating with AutoLayout from code.

    For example you will be able to specify:

    PVVFL(@"[view1]-20-[view2]").fromRightToLeft.withViews(views).asArray
    

    Instead of

    [NSLayoutConstraint constraintsWithVisualFormat:@"[view1]-20-[view2]"
                                            options:NSLayoutFormatDirectionRightToLeft
                                            metrics:nil
                                              views:views]
    

    Also you will be able to group layouts settings, mix VFL and not VFL constraints. Parus able to prevent common mistakes, differentiate location and parameters constriaints, and provide great auto-completion support.

提交回复
热议问题