teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

修正

2016/07/02 23:46

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  暫定対応
18
18
 
19
- フォントを変更することで範囲指定がうまくいったので、BoldフォントがあるフォントでSystemフォントに近いものを使用して以下の様に対応してみました。
19
+ フォントを変更することで範囲指定がうまくいったので、`Bold`があるフォントで`System`フォントに近いものを使用して以下の様に対応してみました。
20
20
 
21
21
  ```swift
22
22
  import UIKit

1

修正

2016/07/02 23:46

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -6,4 +6,49 @@
6
6
  再度お試しください。
7
7
 
8
8
  ![image](4ace25f02e9af964bacf0edbeabb34e1.png)
9
+ ![image](5955c7682f71d878563ad771ee7ec4e2.png)
10
+
11
+ 回答追記
12
+ ---
13
+
14
+ 確かにTextViewだと範囲指定がうまくいかないことを確認しました。
15
+ 調べてみましたが、自分でも解決方法が分かりませんでした、、、(T_T)
16
+
17
+ 暫定対応
18
+
19
+ フォントを変更することで範囲指定がうまくいったので、BoldフォントがあるフォントでSystemフォントに近いものを使用して以下の様に対応してみました。
20
+
21
+ ```swift
22
+ import UIKit
23
+
24
+ class ViewController: UIViewController {
25
+
26
+ @IBOutlet weak var textV1: UITextView!
27
+ @IBOutlet weak var textV2: UITextView!
28
+
29
+ override func viewDidLoad() {
30
+ super.viewDidLoad()
31
+
32
+ let attrText1 = NSMutableAttributedString(string: "test")
33
+ attrText1.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(20), range: NSMakeRange(0, 4))
34
+ attrText1.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(20), range: NSMakeRange(0, 1))
35
+ textV1.attributedText = attrText1
36
+
37
+
38
+
39
+ let attrText2 = NSMutableAttributedString(string: "テスト")
40
+ attrText2.addAttribute(NSFontAttributeName, value: UIFont(name: "AmericanTypewriter", size: 20)!, range: NSMakeRange(0, 3))
41
+ attrText2.addAttribute(NSFontAttributeName, value: UIFont(name: "AmericanTypewriter-Bold", size: 20)!, range: NSMakeRange(0, 1))
42
+
43
+ textV2.attributedText = attrText2
44
+ }
45
+ }
46
+ ```
47
+
48
+ 古い記事ですが、日本語フォントの比較ができたので以下を参考にしました。
49
+ [iOSで使える font familyの一覧画像](http://tuki0918.hatenablog.com/entry/2013/02/16/163334)
50
+
51
+ 結果
9
- ![image](5bed419c78a6b024b391be500ec0f8dd.png)
52
+ ![image](c8d2f182231bb41d8847c051a0567ff4.png)
53
+
54
+ 暫定的な対応ですが参考にしてください。