macOS/iOS API解説

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

目次

attributedAlternateTitle

INDEX>AppKit>NSButton

ボタンを押し込んだときに表示される代理タイトル属性付文字列

Objective-C

@property(copy) NSAttributedString *attributedAlternateTitle

Swift

@NSCopying var attributedAlternateTitle: NSAttributedString

解説

ボタンを押し込んだときに表示される代理タイトル属性付文字列を返します。
ボタンタイプによって、表示するものとしないものがあります。
behaviorがMomentary Changeになっている必要があります
表示するのはRounded Bevel ButtonのMomentary Changeなどです。
初期設定は、「Button」です。

f:id:jjj777:20150228132451g:plain

設定値

Objective-C

NSAttributedString *

Swift

NSAttributedString

属性付代理タイトル文字列

フレームワーク

ApplicationKit

クラス

NSButton

使用可能

10.0

関連記事(外部リンク)

例文

Objective-C

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
	
	NSAttributedString *attStr = [[[NSMutableAttributedString alloc] initWithString:@"Bold Title" 
																		 attributes:[self systemBoldFontAttributes]] autorelease];
	
	[myOutlet setAttributedAlternateTitle:attStr];
	
	NSLog([[myOutlet attributedAlternateTitle] string]);
	
}


- (NSDictionary*)systemBoldFontAttributes {
    return [NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
}
@end

Swift

    //NSButton attributedAlternateTitle
    //http://cocoaapi.hatenablog.com/entry/00011107/NSButton_attributedAlternateTitle
    //Swift2.0
    @IBAction func function008(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//スタイル
        let attributes : Dictionary = [
            NSFontAttributeName : NSFont.systemFontOfSize(19.0),
            NSForegroundColorAttributeName:NSColor.redColor()]
        let attributedString : NSAttributedString =
        NSAttributedString(string: "赤い代替タイトル", attributes: attributes)
        theButton.attributedAlternateTitle = attributedString
        theButton.title = "タイトル"
        theButton.action = Selector("buttonAction002:")//ボタンを押した時に動かす関数
        theButton.target = self//ターゲット
        
        aWindow.contentView!.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

編集時のバージョン

10.11.3