macOS/iOS API解説

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

目次

title

INDEX>AppKit>NSButton

ボタンのタイトル

Objective-C

@property(copy) NSString *title

Swift

var title: String

解説

ボタンのタイトル。
取得する場合タイトルがなければ空の文字列を返します。
初期設定は「Button」です。

f:id:jjj777:20150228133720p:plain

設定値

Objective-C

( NSString * )

Swift

String

タイトル

フレームワーク

ApplicationKit

クラス

NSButton

使用可能

10.0-

関連記事(外部リンク)

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
	[myOutlet setTitle:@"Button title"];
}

@end

Swift

    //NSButton title
    //Swift2.0
    func buttonAction002(sender: AnyObject?){
        //var theWindow : NSWindow = (sender as! NSButton).window!
        NSLog("!!!")
    }
    
    @IBAction func function002(sender: AnyObject) {
        let 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 = "ウインドウタイトル"//タイトル設定
        //
        let theButton : NSButton = NSButton(frame: NSMakeRect(50.0, 50.0, 100.0, 30.0))
        theButton.title = "Change"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("buttonAction002:")
        theButton.target = self
        theButton.setButtonType(.MomentaryLightButton)
        //.SwitchButton
        //.PushOnPushOffButton
        aWindow.contentView!.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

編集時のバージョン

10.11