ios purelayout--基础使用--进阶使用--看这就够了

//******************************基础设置--start*********************************
//
一.视图本身 //1.设置高度 [self.namePhoneLB autoSetDimension:ALDimensionHeight toSize:20]; //2.设定宽高 [self.iconImageView autoSetDimensionsToSize:CGSizeMake(45, 45)]; //二.父子视图 //1.距离父视图某边距10 [self.iconImageView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10]; //2.Y轴居中 [self.iconImageView autoAlignAxisToSuperviewAxis:ALAxisHorizontal]; //3.设置四边约束忽略某个属性 ALEdgeInsets defInsets = ALEdgeInsetsMake(17.5,10,17.5,10);//上左下右 [self.agreeBtn autoPinEdgesToSuperviewEdgesWithInsets:defInsets excludingEdge:ALEdgeLeft]; //三.兄弟视图 //1.设置该视图 的左边距离 到其他视图的右边 10 [self.namePhoneLB autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.iconImageView withOffset:10]; //2.设置该视图与其他视图 同X值 [self.descriseLB autoAlignAxis:ALAxisVertical toSameAxisOfView:self.namePhoneLB]; //3.设置该视图与其他视图 等宽 [self.descriseLB autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.namePhoneLB]; //清除约束 for (NSLayoutConstraint *contrain in self.tempView.superview.constraints) { if ([contrain isEqual:self.tempContraint]) { [self.tempView.superview removeConstraint:contrain]; } } //约束返回值,修改返回值即可修改约束 self.tempContraint = [self.tempView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];

//******************************基础设置--end*********************************
//******************************进阶使用,for循环--start*********************************

UILabel *processLB = [UILabel labelWithLeftText:@"处理过程" color:Color_333333 font:UIFont_28]; [self addSubview:processLB]; NSArray *array = model.exceptionDualArray; UILabel *tempDescLable = nil; UILabel *firstCircleLB = nil; // UILabel *secondCircleLB = nil; for (int i=0; i<array.count; i++) { ExceptionDualModel *dualModel = array[i]; NSString *titleStr = dualModel.handleNotes; NSString *dateStr = [NSString returnYYYYMMddDate:dualModel.handleDate]; UILabel *descLB = [UILabel labelWithLeftText:titleStr color:Color_333333 font:UIFont_24]; descLB.numberOfLines = 0; UILabel *dateLB = [UILabel labelWithLeftText:dateStr color:Color_333333 font:UIFont_24]; //圆点 UILabel *circleLB = [UILabel newAutoLayoutView]; circleLB.backgroundColor = UIColorFromRGB(0xdbdee0); circleLB.layer.cornerRadius = 7/2; circleLB.layer.masksToBounds = YES; [self addSubview:dateLB]; [self addSubview:descLB]; [self addSubview:circleLB]; [dateLB autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kMargin]; [dateLB autoSetDimension:ALDimensionWidth toSize:70]; [dateLB autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:descLB]; [circleLB autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:dateLB withOffset:10]; [circleLB autoSetDimensionsToSize:CGSizeMake(7, 7)]; [circleLB autoAlignAxis:ALAxisHorizontal toSameAxisOfView:dateLB]; [descLB autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kMargin]; [descLB autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:circleLB withOffset:10]; if (i==0) {//第一个 [descLB autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:processLB withOffset:25]; firstCircleLB = circleLB;//第一个圆点 }else{ [descLB autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:tempDescLable withOffset:25]; } tempDescLable = descLB;//保存最后一个 // secondCircleLB = circleLB;//最后一个圆点 } //竖线 UIView *line = [UIView newAutoLayoutView]; line.backgroundColor = UIColorFromRGB(0xdbdee0); [self addSubview:line]; [line autoSetDimension:ALDimensionWidth toSize:1]; [line autoAlignAxis:ALAxisVertical toSameAxisOfView:firstCircleLB]; [line autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:firstCircleLB withOffset:0]; // [line autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:secondCircleLB withOffset:0]; [line autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:tempDescLable withOffset:30]; [processLB autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kMargin]; [processLB autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:15]; [processLB autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kMargin]; // [tempDescLable autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:10];;//最后一个距离父视图 [line autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:10];;//最后一个距离父视图
//******************************进阶使用,for循环--end*********************************
 

//时间轴效果图

 

posted @ 2017-08-26 15:37  justqi  阅读(1017)  评论(0编辑  收藏  举报