macOS/iOS API解説

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

目次

alignment

INDEX>AppKit>NSControl

コントロールの文字揃えを返します

Objective-C

Swift


解説

コントロールの文字揃えを返します。
【NSTextAlignment】
● NSLeftTextAlignment 左揃え
● NSRightTextAlignment 右揃え
● NSCenterTextAlignment センター揃え
● NSJustifiedTextAlignment ジャスティファイ
● NSNaturalTextAlignment 自動(初期設定)
NSNaturalTextAlignmentは文字の言語の自然な配置として、他の配置のうちの1つを使って表示されます。
属性付き文字列(AttrubutedString)が入っていると、そちらが優先されます。

返り値

( NSTextAlignment )

文字揃え

引数

フレームワーク

ApplicationKit

クラス

NSControl

使用可能

10.0

参照

- setAlignment:

例文

#import "scriptSend.h"

@implementation scriptSend

- (IBAction)myAction:(id)sender
{
	[sender setTitle:@"text"];//senderはボタン

	[sender setAlignment:NSLeftTextAlignment];

	[myOutlet setAlignment:[sender alignment]];//senderは別のボタン
	
	switch ([sender alignment]){
	
	case NSLeftTextAlignment:
		{
		NSLog(@"NSLeftTextAlignment");break;
		}
	case NSRightTextAlignment:
		{
		NSLog(@"NSRightTextAlignment");break;
		}
	case NSCenterTextAlignment:
		{
		NSLog(@"NSCenterTextAlignment");break;
		}
	case NSJustifiedTextAlignment:
		{
		NSLog(@"NSJustifiedTextAlignment");break;
		}
	default:
		{
		NSLog(@"NSNaturalTextAlignment");break;
		}
	}

}
@end

更新時のバージョン

OS X 10.10.3
Swift1.2