macOS/iOS API解説

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

目次

allowsMixedState

INDEX>AppKit>NSButton

ボタンの状態がMixedを許すかどうか

Objective-C

@property BOOL allowsMixedState

Swift

var allowsMixedState: Bool

解説

ボタンの状態がMixedかどうか返します。
YESならMixed,on,offの3つの状態(Mixed)
NOならon,offの2つの状態
デフォルトはNoです。

Mixedの状態
f:id:jjj777:20150228162155g:plain

設定値

Objective-C

@property BOOL allowsMixedState

Swift

var allowsMixedState: Bool

YES/NO

フレームワーク

ApplicationKit

クラス

NSButton

使用可能

10.0

参照


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


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

例文

Objective-C

Swift

    //NSButton
    @IBAction func function014(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 theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 90.0, 100.0, 30.0))
        theButton.title = "Change"
        theButton.bezelStyle = NSBezelStyle.RegularSquareBezelStyle
        theButton.setButtonType(NSButtonType.SwitchButton)
        theButton.action = Selector("buttonAction002:")
        theButton.target = self
        theButton.allowsMixedState = true
        
        aWindow.contentView.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }
#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
//senderはボタン
if ([sender allowsMixedState]){
        [sender setTitle:@"YES"];
    }else{
        [sender setTitle:@"NO"];}
    }

@end