2017-03-19 14 views
1

セグメント化されたコントロールを実装しようとしていますが、レイアウトがとてもシンプルです。私はそれをカスタマイズしたい:iOS向けのSwiftでのカスタムセグメント化コントロール

  • はカスタムインジケータ

それを行うにはどうだろう方法を持っているインスタンスの境界線を失いますか?私はAndroidでTabLayoutをカスタマイズする方法を知っていますが、ここで私は正直ではなくなりました。私はこのリストにはなかった、カスタマイズするために必要なものであれば

enter image description here

答えて

0

UISegmentedControl Docs、私は私自身を構築したいです。

イメージでは、2つのボタン、インジケータの表示、ユーザーのやりとりに対応するロジックを使用します。

2

私はかなり遅れて相手にだけど、ここで私がやるだろうと何:

を.clearする背景色合い色を設定し

segmentedControlInstance.backgroundColor = UIColor(red:0.13, green:0.16, blue:0.29, alpha:1.0) 

を.clearする背景色を設定

segmentedControlInstance.tintColor = .clear 

私は選択したセグメントのタイトルが太字であることに気付きました。テキストは二つの状態の属性を設定し

segmentedControlInstance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)], for: .normal) 
    segmentedControlInstance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 16)], for: .selected) 

は最後に、2枚の背景画像を設定する(.normal & .selected)。私はあなたがbarMetricsパラメータで遊んでもらおう

 segmentedControlInstance.setBackgroundImage(UIImage(name: "selectedSegment", for: .selected, barMetrics: ?) 
    segmentedControlInstance.setBackgroundImage(UIImage(name: "normalSegment", for: .normal, barMetrics: ?) 

:注意、私はbarMetricsパラメータに設定するにはどのような見当がつかない。