macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

setNextState

INDEX>AppKit>NSButton

ボタンを次の状態にします

Objective-C

- (void)setNextState

Swift

func setNextState()

解説

ボタンを次の状態にします。
ボタンが3つの状態を持つなら、on/off/Mixedを循環します。
ボタンが2つの状態を持つなら、on/offを切り換えます。

f:id:jjj777:20150228225610g:plain

返り値

Objective-C

- (void)setNextState

Swift

func setNextState()

なし

フレームワーク

ApplicationKit

クラス

NSButton

使用可能

10.0

参照


allowsMixedState - Cocoa API解説(iOS/OS X)


setAllowsMixedState: - Cocoa API解説(iOS/OS X)

例文

Objective-C

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
	[myOutlet setAllowsMixedState:YES];
	[myOutlet setNextState];
}

@end

Swift

    //NSButton setNextState
    var switchButton: NSButton!
    func buttonAction016(sender: AnyObject?){
        var theWindow : NSWindow = (sender as NSButton).window!
        switchButton.setNextState()
        NSLog("!!!")
    }
    @IBAction func function016(sender: AnyObject) {
        var aWindow : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            defer: false,
            screen: NSScreen.mainScreen())
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        //
        var theSwitch : NSButton = NSButton(frame: NSMakeRect(100.0, 90.0, 100.0, 30.0))
        theSwitch.title = "Switch"
        theSwitch.bezelStyle = NSBezelStyle.RegularSquareBezelStyle
        theSwitch.setButtonType(NSButtonType.SwitchButton)
        theSwitch.action = Selector("buttonAction002:")
        theSwitch.target = self
        switchButton = theSwitch
        theSwitch.allowsMixedState = true
        theSwitch.state = NSMixedState
        aWindow.contentView.addSubview(theSwitch)
        
        var theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 50.0, 100.0, 30.0))
        theButton.title = "Change"
        theButton.bezelStyle = NSBezelStyle.RegularSquareBezelStyle
        theButton.action = Selector("buttonAction016:")
        theButton.target = self
        theButton.allowsMixedState = true
        aWindow.contentView.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
        
        
    }