Button ja - Tai-Kimura/SwiftJsonUI GitHub Wiki

🇺🇸 English | 🇯🇵 日本語

Button

class: SJUIButton inherits: UIButton

Button の属性

属性名 UIKit SwiftUI Compose XML jsonでの型 詳細 備考
text string NSLocalizedString(text, comment:"")がattributedTextに設定されます。
font string ボタンのフォント名。
fontSize float ボタンのフォントサイズ。
fontColor string NSAttributedStringKey.foregroundColor。
hilightColor string ビューがハイライトされたときにfontColorがこの色に変更されます。
disabledFontColor string ビューが無効になったときにfontColorがこの色に変更されます。
disabledBackground string ビューが無効になったときにbackgroundColorがこの色に変更されます。
enabled boolean view.isEnabled。
image string ボタンの背景画像。
config dictionary UIButton.Configuration(iOS 15+)の設定。
onclick string この属性でonclickイベントを定義できます。この属性で作成されたセレクターが、UIControlEvents.touchUpInsideイベントのボタンに設定されます。
onclick JSON array この属性でイベントを定義できます。この属性で作成されたセレクターがボタンの各イベントに設定されます。利用可能なキー:selector: ボタンにアタッチされるSelectorevents: Selectorに関連付けるイベントを指定する文字列配列Down: UIControlEvents.touchDownDownRepeat: UIControlEvents.touchDownRepeatDragInside: UIControlEvents.touchDragInsideDragOutside: UIControlEvents.touchDragOutsideDragEnter: UIControlEvents.touchDragEnterDragExit: UIControlEvents.touchDragExitUpInside: UIControlEvents.touchUpInsideUpOutside: UIControlEvents.touchUpOutsideCancel: UIControlEvents.touchCancelAll: UIControlEvents.allTouchEvents

Button のプロパティ

静的プロパティ

open class var viewClass: SJUIButton.Type

このプロパティは、createFromJSONメソッドでどのクラスをインスタンス化するかを決定するために使用されます。 SJUIButtonを継承するクラスを作成する際は、このプロパティでビューのクラスを定義する必要があります。

インスタンスプロパティ

public var defaultFontColor: UIColor?

通常状態のデフォルトフォント色。特定の色が設定されていない場合のベーステキスト色として使用されます。

public var disabledBackgroundColor: UIColor?

ボタンが無効(isEnabled = false)の場合に適用される背景色。

public var disabledFontColor: UIColor?

ボタンが無効(isEnabled = false)の場合に適用されるテキスト色。

オーバーライドプロパティ

override var isEnabled: Bool

ボタンの有効状態。falseに設定すると、自動的に無効色が適用されます。 有効状態と無効状態間の色遷移を管理するカスタムセッター。

Button の関数

静的メソッド

public class func createFromJSON(attr: JSON, target: Any, views: inout [String: UIView]) -> SJUIButton

ボタンがJSONファイルから作成される際に呼び出されるファクトリメソッド。 SJUIButtonクラスを継承するクラスを作成する際は、このメソッドをオーバーライドしてください。

オーバーライドメソッド

override func setTitleColor(_ color: UIColor?, for state: UIControl.State)

無効色管理システムと統合されたカスタムタイトル色設定。 ボタンの状態に基づいて色遷移を自動的に処理します。

継承メソッド

SJUIButtonはUIButtonとSJUIViewからすべてのメソッドを継承します:

  • SJUIViewからのタッチ処理メソッド
  • イベント処理機能
  • 制約とレイアウト管理
  • ジェスチャー認識サポート

イベント処理

ボタンはonclick属性を通じて包括的なイベント処理をサポートします:

  • touchUpInsideイベント用の単一文字列セレクター
  • 複数のイベントタイプとセレクター用のJSON配列形式
  • UIControl.Eventシステムとの統合
  • すべての標準ボタンイベント(touchDown、touchUpInsideなど)のサポート