OC封装一个自动显示信息的功能
- (void)createInfoRowWithTitle:(NSString *)title detail:(NSString *)detail addToStack:(UIStackView *)stack {
UIStackView *rowStack = [[UIStackView alloc] init];
rowStack.axis = UILayoutConstraintAxisHorizontal;
rowStack.distribution = UIStackViewDistributionFill;
rowStack.alignment = UIStackViewAlignmentCenter;
rowStack.spacing = 15;
// 标题标签
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = title;
titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
titleLabel.textColor = [UIColor darkGrayColor];
titleLabel.widthAnchor.constraint(equalToConstant: 120).active = YES;
// 详情标签
UILabel *detailLabel = [[UILabel alloc] init];
detailLabel.text = detail;
detailLabel.font = [UIFont systemFontOfSize:16];
detailLabel.textColor = [UIColor blackColor];
detailLabel.textAlignment = NSTextAlignmentRight;
detailLabel.setContentHuggingPriority(UILayoutPriorityDefaultLow, forAxis:UILayoutConstraintAxisHorizontal);
[rowStack addArrangedSubview:titleLabel];
[rowStack addArrangedSubview:detailLabel];
[stack addArrangedSubview:rowStack];
}
done

浙公网安备 33010602011771号