如何以编程方式设置setContentHuggingPriority

时间:2019-08-08 05:53:19

标签: ios swift autolayout

我正在以编程方式创建视图,但是我无法设置 FileInputStream excelFile = new FileInputStream(new File(path)); Workbook workbook = new XSSFWorkbook(excelFile); Sheet dataTypeSheet = workbook.getSheetAt(0); for (Row currentRow : dataTypeSheet) { Iterator<Cell> cellIterator = currentRow.iterator(); while (cellIterator.hasNext()) { Cell currentCell = cellIterator.next(); int colIndex = currentCell.getColumnIndex(); ............... } } 来工作。 这是当前结果:

the red space should be equals the button

setContentHuggingPriority

1 个答案:

答案 0 :(得分:1)

您正在寻找按钮适合其内容的状态,然后标签将留有任何剩余空间并用多行文本填充。

由于您使用的是多行标签,因此也应同时设置contentCompressionResistancePriority

button.setContentCompressionResistancePriority(.required, for: .horizontal)

label.setContentCompressionResistancePriority(.required, for: .horizontal)