0
我创建了动态按钮。我需要根据标题文字改变按钮的宽度。这是我的代码。如何在swift 3中基于动态创建按钮的文本设置按钮宽度?
for i in 0..<holdingSize {
let button = UIButton(type: .custom)
if i == 0 {
frame = CGRect(x: 10, y: 5, width: 100, height: 30)
}else{
buttonY = buttonY + 110
frame = CGRect(x: buttonY, y: 5, width: 100, height: 30)
}
button.setTitle("\(arrayOfHoldings[i])", for: UIControlState.normal) // We are going to use the item name as the Button Title here.
button.titleLabel?.text = "\(arrayOfHoldings[i])"
button.titleLabel?.font = UIFont(name: (button.titleLabel?.font.fontName)!, size: 15)
button.setTitleColor(Colors.green, for: .normal)
button.sizeToFit()
}
对于3.0我修改这些线'''让标签=的UILabel(帧:的CGRect(X:0,Y:0,宽度:maxWidth,高度:30))''' –
它的working..thank你这么多@Rakshith Nandish –
@SathishKumar太棒了!如果您将此标记为正确答案buddy.cheers,将不胜感激! :) –