如何将2个动态宽度UILabel放置到具有砌体约束的视图中?

时间:2017-01-21 16:11:40

标签: ios masonry ios-autolayout

我真的很喜欢砌体库。它使我免于Apple的Autolayout冲突。

我用这个库解决了我的大部分问题。但有一件事我无法实现。

同一个UIView中有2个标签。两个标签都有动态宽度。我写了这段代码并发生了问题

pca = PCA(inputCol = 'features')
dt = DecisionTreeRegressor(featuresCol=pca.getOutputCol(), 
                           labelCol="energy")
pipe = Pipeline(stages=[pca,dt])

paramgrid = ParamGridBuilder().addGrid(pca.k, range(1,50,2)).addGrid(dt.maxDepth, range(1,10,1)).build()

tvs = TrainValidationSplit(estimator = pipe, evaluator = RegressionEvaluator(
labelCol="energy", predictionCol="prediction", metricName="mae"), estimatorParamMaps = paramgrid, trainRatio = 0.66)

model = tvs.fit(wind_tr_va);

Problem

我应该怎么做才能避免这类问题?

1 个答案:

答案 0 :(得分:0)

我用这段代码解决了我的问题:

    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bottomContainer.centerY);
        make.left.equalTo(self.left).with.offset(@10);
        make.trailing.equalTo(self.priceLabel.leading);
    }];

    [self.priceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bottomContainer.centerY);
        make.right.equalTo(self.right).with.offset(@-10);
    }];


    [self.priceLabel setContentCompressionResistancePriority: UILayoutPriorityDefaultHigh forAxis: UILayoutConstraintAxisHorizontal];
    [self.nameLabel setContentCompressionResistancePriority: UILayoutPriorityDefaultLow forAxis: UILayoutConstraintAxisHorizontal];

谢谢