0
でリサイズUIButtonの背景を追加します。ただし私は勾配でUIButtonに背景を追加することができ、このコードでグラデーションカラー
public func addBackgroundAndGradient(to: UIView, gradient1: CGColor, gradient2: CGColor, cornerRadius: CGFloat = 5){
let backgroundImage = UIImageView()
backgroundImage.frame.size = to.frame.size
backgroundImage.clipsToBounds = true
backgroundImage.layer.borderColor = UIColor.white.cgColor
backgroundImage.layer.borderWidth = 0.5
to.insertSubview(backgroundImage, at: 0)
let gradient = CAGradientLayer()
let gradient1 = UIColor(red: 200/255, green: 100/255, blue: 5/255, alpha: 1).cgColor
let gradient2 = UIColor(red: 1, green: 128/255, blue: 0, alpha: 1).cgColor
gradient.colors = [gradient1, gradient2, gradient2, gradient1]
gradient.locations = [0.0, 0.35, 0.65, 1.0]
gradient.frame.size = to.frame.size
backgroundImage.layer.addSublayer(gradient)
backgroundImage.layer.cornerRadius = cornerRadius
}
を私はUIButtonのための新しいタイトルを設定すると、背景がサイズ変更されません。テキストをイニシャルよりも長くすると、テキストはバックグラウンドを超えます。
UIButtonのグラデーションを使用して背景のサイズを変更するにはどうすればよいですか?これを行うための