回答編集履歴

1

アンダーラインに関する記述

2015/02/19 12:38

投稿

noppefoxwolf
noppefoxwolf

スコア231

test CHANGED
@@ -1,6 +1,4 @@
1
-
2
-
3
- TextAttributesを利用します
1
+ 色を変えるにはTextAttributesを利用します
4
2
 
5
3
 
6
4
 
@@ -10,10 +8,40 @@
10
8
 
11
9
 
12
10
 
13
- [button setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
11
+ [button setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]} forState:UIControlStateNormal];
14
12
 
15
13
 
16
14
 
17
15
  self.navigationItem.rightBarButtonItem = button;
18
16
 
19
17
  ```
18
+
19
+
20
+
21
+ NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)
22
+
23
+ で下線も引けるはずですが、うまく動作しませんでした。
24
+
25
+
26
+
27
+ UIButtonを生成しUIBarbuttonとして入れ込む方法もあります
28
+
29
+ ```lang-objc
30
+
31
+ UIButton*button2 = [UIButton buttonWithType:UIButtonTypeCustom];
32
+
33
+ NSAttributedString*title = [[NSMutableAttributedString alloc] initWithString:@"ボタン" attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)}];
34
+
35
+ [button2 setAttributedTitle:title forState:UIControlStateNormal];
36
+
37
+ [button2 sizeToFit];
38
+
39
+ UIBarButtonItem*left = [[UIBarButtonItem alloc] initWithCustomView:button2];
40
+
41
+
42
+
43
+ self.navigationItem.leftBarButtonItem = left;
44
+
45
+ ```
46
+
47
+