attributedAlternateTitle
ボタンを押し込んだときに表示される代理タイトル属性付文字列
@property(copy) NSAttributedString *attributedAlternateTitle
@NSCopying var attributedAlternateTitle: NSAttributedString
解説
ボタンを押し込んだときに表示される代理タイトル属性付文字列を返します。
ボタンタイプによって、表示するものとしないものがあります。
behaviorがMomentary Changeになっている必要があります
表示するのはRounded Bevel ButtonのMomentary Changeなどです。
初期設定は、「Button」です。
フレームワーク
ApplicationKit
クラス
NSButton
使用可能
10.0
関連記事(外部リンク)
例文
#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
//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