实现两个label前后对齐

实现两个label前后对齐_第1张图片
image.png

一看就是令人头疼的UI设计

        UILabel *dateLabel = [[UILabel alloc]init];
        dateLabel.frame = CGRectMake(UI_View_Width-30-200, 33, 200, 15);
        dateLabel.font = [UIFont systemFontOfSize:15];
        dateLabel.textColor = BB_White_Color;
        dateLabel.textAlignment = NSTextAlignmentRight;
        dateLabel.text = [NSString stringWithFormat:@"还款日期  %@",_dataSource[@"date"]];
        [cell.contentView addSubview:dateLabel];
        
        UILabel *amountLabel = [[UILabel alloc]init];
        amountLabel.frame = CGRectMake(UI_View_Width-30-200, 72, 200, 15);
        amountLabel.font = [UIFont systemFontOfSize:15];
        amountLabel.textColor = BB_White_Color;
        amountLabel.textAlignment = NSTextAlignmentRight;
        amountLabel.text = [NSString stringWithFormat:@"借款金额  %@元",_dataSource[@"amount"]];
        [cell.contentView addSubview:amountLabel];
        
        if ([dateLabel sizeThatFits:CGSizeMake(UI_View_Width-30, 15)].width>[amountLabel sizeThatFits:CGSizeMake(UI_View_Width-30, 15)].width) {
            NSString *space = @" ";
            for (int i=0; i=[amountLabel sizeThatFits:CGSizeMake(UI_View_Width-30, 15)].width) {
                    break;
                }
                space = [space stringByAppendingString:@" "];
            }
        }

你可能感兴趣的:(实现两个label前后对齐)