質問編集履歴

5

タイトルの修正

2018/11/09 08:59

投稿

affluenceyou
affluenceyou

スコア44

test CHANGED
@@ -1 +1 @@
1
- UITextViewでのattributedTextの扱い方について
1
+ UITextViewでのattributedTextにおいて、日本語の扱い方について
test CHANGED
File without changes

4

誤字の訂正

2018/11/09 08:59

投稿

affluenceyou
affluenceyou

スコア44

test CHANGED
File without changes
test CHANGED
@@ -96,8 +96,6 @@
96
96
 
97
97
  }
98
98
 
99
+ ```
100
+
99
101
  で上のコードを呼び出すことで、「入力確定時」に期待した色になることを確認できました。しかし変換中は30文字を超えていてもずっと黒いままであり、変換終了後に一気に赤くなるような仕様になってしまいます。これを解決する方法はあるのでしょうか?
100
-
101
-
102
-
103
- ```

3

textView.markedTextRangeで変換確定後は期待した動きになることを確認

2018/11/09 08:50

投稿

affluenceyou
affluenceyou

スコア44

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,23 @@
81
81
  追記1
82
82
 
83
83
  英語だとうまくいっていることがわかりました。これは日本語の扱いによる問題なのでしょうか? だとするとどうすれば解決できるのか... ご教示して頂けると嬉しいです。
84
+
85
+
86
+
87
+ 追記2
88
+
89
+ やはり日本語変換の問題だと判明しました。
90
+
91
+ ```swift
92
+
93
+ if(textView.markedTextRange == nil) {
94
+
95
+ myTextViewDelegate?.textViewDidChange(textView: textView)
96
+
97
+ }
98
+
99
+ で上のコードを呼び出すことで、「入力確定時」に期待した色になることを確認できました。しかし変換中は30文字を超えていてもずっと黒いままであり、変換終了後に一気に赤くなるような仕様になってしまいます。これを解決する方法はあるのでしょうか?
100
+
101
+
102
+
103
+ ```

2

英語だとうまくいっていることが判明

2018/11/09 08:48

投稿

affluenceyou
affluenceyou

スコア44

test CHANGED
File without changes
test CHANGED
@@ -75,3 +75,9 @@
75
75
  どなたかご教示して頂けると幸いです。
76
76
 
77
77
  よろしくお願いします。
78
+
79
+
80
+
81
+ 追記1
82
+
83
+ 英語だとうまくいっていることがわかりました。これは日本語の扱いによる問題なのでしょうか? だとするとどうすれば解決できるのか... ご教示して頂けると嬉しいです。

1

subStringの方法を変えましたが、依然として同じ問題が残ってしまいます

2018/11/09 08:36

投稿

affluenceyou
affluenceyou

スコア44

test CHANGED
File without changes
test CHANGED
@@ -42,11 +42,9 @@
42
42
 
43
43
 
44
44
 
45
- let from = textView.text.index(textView.text.startIndex, offsetBy: 29)
45
+ let from = textView.text.index(textView.text.startIndex, offsetBy: 30)
46
46
 
47
- let to = textView.text.index(from, offsetBy: textView.text.count - 30)
48
-
49
- let disenabledText = NSMutableAttributedString(string: String(textView.text[from...to]), attributes: disenabledStringAttributes)
47
+ let disenabledText = NSMutableAttributedString(string: String(textView.text[from...]), attributes: disenabledStringAttributes)
50
48
 
51
49
 
52
50
 
@@ -66,13 +64,11 @@
66
64
 
67
65
  しかしこれだと、なぜか30文字を超えた入力からおかしな挙動になります。以下のスクリーンショットは、30文字目入力時点、31文字目に「お」を入力した時点、32文字目に「い」を入力したものになります。
68
66
 
69
- ![イメージ説明](32d040023a6fc689d80d3dd37b3e8f44.png)
67
+ ![イメージ説明](28a41824d1cee093a7064c25a7dfebc9.png)
70
68
 
71
- ![イメージ説明](57d34a96eab778ef78e2b3d8b32e06c7.png)
69
+ ![イメージ説明](b5ce4bdde4c937503e1cbb0c2afb4bd7.png)
72
70
 
73
- ![イメージ説明](05e4c1b59f50a92a2d92559ec27eaf21.png)
71
+ ![イメージ説明](bad5929d57a88723cf13ca43d3a62fb9.png)
74
-
75
-
76
72
 
77
73
  そもそもの方向性が違うのか、少し変えればできるのか、しばらく格闘してみましたがわかりませんでした。
78
74