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,將不勝感激! :) –