UISegmentedControl
の値は、プログラムによってswiftを使用して入力できますか?swiftを使用してプログラムでUISegmentedControlを塗り潰す
1
A
答えて
4
let segmentedControl = UISegmentedControl()
segmentedControl.insertSegment(withTitle: "Title", at: 0, animated: true)
segmentedControl.setTitle("Another Title", forSegmentAt: 0)
1
は、私は、@ RyuX51 の溶液を使用して、私の問題を解決し、私のコードは以下のようになります。
class MyCustomViewController: UIViewController{
@IBOutlet weak var ServicesSC: UISegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
ServicesSC.removeAllSegments()
ServicesSC.insertSegment(withTitle: "Title", at: 0, animated: true)
ServicesSC.setTitle("Another Title", forSegmentAt: 0)
}
}
2
私が勘違いしておりません場合は、あなたがセグメントに「UISegmentedControl」を追加することを意味インターフェイスビルダを使用せずに、プログラムでコンポーネントを実行できます。
はい、それは可能である:
// Assuming that it is an "IBOutlet", you can do this in your "ViewController":
class ViewController: UIViewController {
@IBOutlet weak var segmentedControl: UISegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
// remove all current segments to make sure it is empty:
segmentedControl.removeAllSegments()
// adding your segments, using the "for" loop is just for demonstration:
for index in 0...3 {
segmentedControl.insertSegmentWithTitle("Segment \(index + 1)", atIndex: index, animated: false)
}
// you can also remove a segment like this:
// this removes the second segment "Segment 2"
segmentedControl.removeSegmentAtIndex(1, animated: false)
}
// and this is how you can access the changing of its value (make sure that event is "Value Changed")
@IBAction func segmentControlValueChanged(sender: UISegmentedControl) {
print("index of selected segment is: \(sender.selectedSegmentIndex)")
}
}
関連する問題
- 1. Swift 3コレクションビューでのラベルの塗り潰しが不明確
- 2. CursorLoaderを使用してリストビューを塗り潰す前に進捗インジケータを表示
- 3. リストビューの行を塗り潰す方法
- 4. Windowsフォームでコンボボックスを塗り潰す方法C#
- 5. jquery ajaxでドロップダウンを塗り潰すASP.NET MVC
- 6. SVGの塗り潰し部分(ビットマップ)を反転して鏡像にします
- 7. 多角形SVG形状を塗り潰す画像
- 8. UISegmentedControl Swiftのターゲットの割り当て3
- 9. JCrop塗り潰されていない選択変数
- 10. 自動塗り潰しコンテナCSSブートストラップとイメージ
- 11. 基本クラスの配列で派生クラスの配列を塗り潰すリフレクションを使用
- 12. UISegmentedControlのテキストをプログラムで
- 13. UISegmentedControlを使用してMKMapViewとUITableViewに切り替えます。
- 14. UISegmentedControlを使用して2つのビューを切り替える
- 15. アンドロイド8.0で枠組み設定の自動塗り潰し設定画面へ
- 16. SWIFTを使用してプログラムでカスタムUITableViewCellを作成する
- 17. SWIFTを使用してassets.xcassetsパスをプログラムで図解する
- 18. 塗りつぶしプログラム
- 19. UILabelレイヤの背景色部分的な塗り潰しが発生しない
- 20. CGContextでグラデーションを使用してシェイプを塗りつぶす
- 21. ビットマップXMLでVectorDrawableを使用して色を塗りつぶし
- 22. ビューポートに入っているときにプログレスバーを塗り潰すか空になるようにします。
- 23. Swift 3でJSONデータを使って表を塗りつぶす方法は?
- 24. NSInvalidArgumentException UISegmentedControlの使用
- 25. UIViewContentModeScaleAspectFitを使用してビューを塗りつぶしますか?
- 26. Graphics2Dを使用して透明で塗りつぶし
- 27. UINavigationController + UITabBarController + TableView/MapViewを使用したUISegmentedControl
- 28. IBを使用してUISegmentedControlをNavigationBarに追加する
- 29. swiftとUIViewAnimationを使用して徐々に図形を塗りつぶしますか?
- 30. FilteringFilterCriteraを使用して行を塗りつぶす