1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DTGradientButtonライブラリを使ってみた

Posted at

DTGradientButtonを使ってボタンをアレンジしてみました

#環境
・Mac Book Pro(macOS:BigSur)
・Xcode(ver:12.5)

#実装例
スクリーンショット 2021-05-20 19.43.11.png

#コード例

ViewController.swift
class ViewController: UIViewController {

    @IBOutlet weak var gradientButton1: UIButton!
    @IBOutlet weak var gradientButton2: UIButton!
    @IBOutlet weak var gradientButton3: UIButton!
    @IBOutlet weak var gradientButton4: UIButton!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        let colors1 = [UIColor(named:"Color1")!, UIColor(named: "Color2")!]
        let colors2 = [UIColor(named:"Color3")!, UIColor(named: "Color4")!]
        let colors3 = [UIColor(named:"Color5")!, UIColor(named: "Color6")!]
        let colors4 = [UIColor(named:"Color7")!, UIColor(named: "Color8")!]
        
        gradientButton1.setGradientBackgroundColors(colors1, direction: .toTop, for: .normal)
        gradientButton1.layer.cornerRadius = 10.0
        gradientButton1.layer.masksToBounds = true
        
        gradientButton2.setGradientBackgroundColors(colors2, direction: .toBottom, for: .normal)
        gradientButton2.layer.cornerRadius = 10.0
        gradientButton2.layer.masksToBounds = true
        
        gradientButton3.setGradientBackgroundColors(colors3, direction: .toBottomLeft, for: .normal)
        gradientButton3.layer.cornerRadius = 10.0
        gradientButton3.layer.masksToBounds = true
        
        gradientButton4.setGradientBackgroundColors(colors4, direction: .toBottomRight, for: .normal)
        gradientButton4.layer.cornerRadius = 10.0
        gradientButton4.layer.masksToBounds = true   
    }
}

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?