我有我創建的 UIButton,就像這樣
let btn = UIButton()
view.addSubview(btn)
btn.setImage(UIImage(systemName: "star"), for: .normal)
btn.translatesAutoresizingMaskIntoConstraints = false
btn.frame = CGRect(x: 30, y: 30, width: 150, height: 150)
btn.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 35).isActive = true
btn.rightAnchor.constraint(equalTo: btnDelete.leftAnchor, constant: 0).isActive = true
btn.heightAnchor.constraint(equalToConstant: 44).isActive = true
btn.widthAnchor.constraint(equalToConstant: 44).isActive = true
問題是我看到了星形圖示按鈕,但我找不到讓它變大并改變星形本身顏色的方法,目前它是藍色的,但我需要它是白色的。
uj5u.com熱心網友回復:
為了使它更大,請使用下面的代碼來填充你給出的寬度和高度btn.frame:
btn.contentHorizontalAlignment = .fill
btn.contentVerticalAlignment = .fill
為了使它改變圖示的??顏色使用:
btn.tintColor = .white
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/386161.html
