zoukankan      html  css  js  c++  java
  • UIStackView上手教程

    https://www.jianshu.com/p/19fbf3ee2840

    https://www.cnblogs.com/bokeyuanlibin/p/5693575.html

    https://www.cnblogs.com/breezemist/p/5776552.html

    对于宽度不一致的SubViews ,需要用约束控制其自定义的宽度or高度 ,可以用masonry

    例子:

    UIStackView *stackContainerView = [[UIStackView alloc] init];

        self.stackContainerView = stackContainerView;

        stackContainerView.axis = UILayoutConstraintAxisHorizontal;

        stackContainerView.spacing = 4 ;

        stackContainerView.alignment = UIStackViewAlignmentFill;

        stackContainerView.distribution = UIStackViewDistributionEqualSpacing;

        [self.contentView addSubview:stackContainerView];

        

        CGFloat stackViewWidth = 0;

    //    创建标签view

        

        for (int i = 0; i < self.recommendModel.marketing.count; i ++) {

           

                NSString *tagKey = self.recommendModel.marketing[i];

                MZTagView *tagview = [[MZTagView alloc] initWithTagKey:tagKey];

                [stackContainerView addArrangedSubview:tagview];

                [tagview mas_makeConstraints:^(MASConstraintMaker *make) {

                    make.centerY.equalTo(stackContainerView);

                    make.width.mas_equalTo(tagview.tagViewWidth);

                    make.height.mas_equalTo( 20 *MZ_RATE);

                }];

                

                stackViewWidth += tagview.tagViewWidth;

            

            

        }

        stackViewWidth += (self.recommendModel.marketing.count-1)*4;

        [stackContainerView mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.equalTo(self.avatorView);

            make.width.mas_equalTo(stackViewWidth);

            make.height.mas_equalTo(20 );

            make.right.equalTo(self.contentView).offset(-16);

        }];

        

  • 相关阅读:
    PAT乙级1002. 写出这个数 (20)
    PAT乙级1001. 害死人不偿命的(3n+1)猜想 (15)
    HDU 4520 小Q系列故事——最佳裁判
    POJ 3414 Pots(BFS)
    POJ 1118 Lining Up
    POJ 2484 A Funny Game
    POJ 2231 Moo Volume
    HDU 5718 Oracle(高精度)
    FZU 1502 Letter Deletion(DP)
    HDU 1564 Play a game
  • 原文地址:https://www.cnblogs.com/huaida/p/11233211.html
Copyright © 2011-2022 走看看