1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NSButtonのタイトルの色を変更

Posted at
NSButton *button = [[NSButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 30.0f, 20.0f)];

NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; 
// 色の設定
[attributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
// アラインメントの設定        
 NSMutableParagraphStyle *style = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy];
 [style setAlignment:NSCenterTextAlignment];
 [attributes setObject:style forKey:NSParagraphStyleAttributeName];

NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:@"button" attributes:attributes];
[button setAttributedTitle:attributedTitle];
[self.view addSubview:button];

NSAttributedStringでタイトルを設定すると、Button Cellのアラインメントが無効になるので
NSParagraphStyleでアラインメントを設定する。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?