macOS/iOS API解説

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

目次

alternateTitle

INDEX>AppKit>NSButton

ボタンを押し込んだときに表示される代理タイトル文字を返します

Objective-C

@property(copy) NSString *alternateTitle

Swift

var alternateTitle: String

解説

ボタンを押し込んだときに表示される代替タイトル文字を返します。
表示することが出来なければ空白になります。
ボタンタイプによって、表示するものとしないものがあります。
behaviorがMomentary Changeになっている必要があります。
表示するのはNSBezelStyle.RegularSquareBezelStyleのNSButtonType.MomentaryChangeButtonなど
初期設定の文字は、「Button」です。

f:id:jjj777:20150226231627p:plain

f:id:jjj777:20150226233016p:plain

f:id:jjj777:20150227075441g:plain

設定値

Objective-C

NSString *

Swift

String

代理タイトル文字列

フレームワーク

ApplicationKit

クラス

NSButton

使用可能

10.0

関連記事(外部リンク)

例文

Objective-C

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
	[myOutlet setTitle:[myOutlet alternateTitle]];
}

@end

Swift

    //NSButton alternateTitle
    //http://cocoaapi.hatenablog.com/entry/00011108/NSButton_alternateTitle
    @IBOutlet weak var alter: NSButton!
    @IBAction func function005(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, 100.0))
        theButton.title = "Change"//タイトル
        theButton.alternateTitle = "Alter"
        
        //alternateTitleを表示するには
        //MomentaryChangeButtonである必要がある
        theButton.setButtonType(NSButtonType.MomentaryChangeButton)//
        //RegularSquareBezelStyleである必要がある。
        theButton.bezelStyle = NSBezelStyle.RegularSquareBezelStyle//スタイル

        theButton.action = Selector("buttonAction002:")//ボタンを押した時に動かす関数
        theButton.target = self//ターゲット
        
        aWindow.contentView!.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

編集時のバージョン

10.11.2