setButtonType:
ボタンタイプをセットします
- (void)setButtonType:(NSButtonType)aType
Swift
func setButtonType(_ aType: NSButtonType)
解説
ボタンタイプをセットします。


【NSButtontype】
● NSMomentaryLight
● NSMomentaryPushButton
● NSMomentaryChangeButton
● NSPushOnPushOffButton on/offボタン
● NSOnOffButton
● NSToggleButton
● NSSwitchButton チェックボックス
● NSRadioButton ラジオボタン
返り値
なし
フレームワーク
ApplicationKit
クラス
NSButton
使用可能
10.0-
関連記事(外部サイト)
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { //senderはボタン [sender setButtonType : NSToggleButton ]; } @end
Swift
//NSButton setButtonType //Swift2.0 @IBAction func function001(sender: AnyObject) { myButton.setButtonType(NSButtonType.PushOnPushOffButton) // MomentaryLightButton // was NSMomentaryPushButton // PushOnPushOffButton // ToggleButton // SwitchButton // RadioButton // MomentaryChangeButton // OnOffButton // MomentaryPushInButton // was NSMomentaryLight }
Swift UI
// // ContentView.swift // setButtonType_ // // Created on 2025/02/24. // NSButton ButtonType import SwiftUI import AppKit //カスタムボタンを作成 struct CustomButton: NSViewRepresentable { let title: String let type: NSButton.ButtonType let action: () -> Void func makeNSView(context: Context) -> NSButton { let button = NSButton(title: title, target: context.coordinator, action: #selector(Coordinator.buttonClicked)) button.setButtonType(type) return button } func updateNSView(_ nsView: NSButton, context: Context) { nsView.title = title } func makeCoordinator() -> Coordinator { Coordinator(action: action) } class Coordinator: NSObject { let action: () -> Void init(action: @escaping () -> Void) { self.action = action } @objc func buttonClicked() { action() } } } struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") CustomButton(title: "カスタムボタン", type: .momentaryPushIn) { print("ボタンが押されました") } .frame(width: 200) } .padding() } } #Preview { ContentView() }
更新時のバージョン
macOS 15.3.1