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

回答編集履歴

5

修正

2016/05/04 15:24

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -11,8 +11,12 @@
11
11
  System Fontではガタつくことはありませんでした。
12
12
 
13
13
  ```swift
14
- // 現在コードの中以下を追加(viewDidAppearとかでOK)
14
+ // ラベルIBOutletdidSetを追加
15
+ @IBOutlet private var countLabel: UILabel? {
16
+ didSet {
15
- countLabel.font = countLabel.font.monospacedDigitFont
17
+ countLabel.font = countLabel.font.monospacedDigitFont
18
+ }
19
+ }
16
20
 
17
21
 
18
22
  // 以下はextensionとしてViewControllerの外に置いてください。

4

修正

2016/05/04 15:24

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,4 +1,35 @@
1
1
  ラベルのフォントを等幅フォントに変更してみてください。
2
2
 
3
3
  例: Courier Regular
4
- ![image](c1bc72f355772f95aa4bb75f8cf0f43c.png)
4
+ ![image](c1bc72f355772f95aa4bb75f8cf0f43c.png)
5
+
6
+
7
+ [How to get monospaced numbers in UILabel on iOS 9](http://stackoverflow.com/questions/30854690/how-to-get-monospaced-numbers-in-uilabel-on-ios-9)
8
+
9
+ 上記の様な記事も見つけました、以下の様に組み込むとフォントを変更しなくても
10
+ 見た目はやりたいことの様になるかもしれません。
11
+ System Fontではガタつくことはありませんでした。
12
+
13
+ ```swift
14
+ // 現在のコードの中に以下を追加(viewDidAppearとかでOK)
15
+ countLabel.font = countLabel.font.monospacedDigitFont
16
+
17
+
18
+ // 以下はextensionとしてViewControllerの外に置いてください。
19
+ extension UIFont {
20
+ var monospacedDigitFont: UIFont {
21
+ let oldFontDescriptor = fontDescriptor()
22
+ let newFontDescriptor = oldFontDescriptor.monospacedDigitFontDescriptor
23
+ return UIFont(descriptor: newFontDescriptor, size: 0)
24
+ }
25
+ }
26
+
27
+ private extension UIFontDescriptor {
28
+ var monospacedDigitFontDescriptor: UIFontDescriptor {
29
+ let fontDescriptorFeatureSettings = [[UIFontFeatureTypeIdentifierKey: kNumberSpacingType, UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector]]
30
+ let fontDescriptorAttributes = [UIFontDescriptorFeatureSettingsAttribute: fontDescriptorFeatureSettings]
31
+ let fontDescriptor = self.fontDescriptorByAddingAttributes(fontDescriptorAttributes)
32
+ return fontDescriptor
33
+ }
34
+ }
35
+ ```

3

修正

2016/05/04 15:13

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,4 +1,4 @@
1
1
  ラベルのフォントを等幅フォントに変更してみてください。
2
2
 
3
- 例: Courier Regular等...
3
+ 例: Courier Regular
4
- ![image説明](c1bc72f355772f95aa4bb75f8cf0f43c.png)
4
+ ![image](c1bc72f355772f95aa4bb75f8cf0f43c.png)

2

修正

2016/05/04 14:31

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,4 +1,4 @@
1
1
  ラベルのフォントを等幅フォントに変更してみてください。
2
2
 
3
- 例: Helvetica Regular等...
3
+ 例: Courier Regular等...
4
- ![image](36b059c6b8ffae7ec1e5394250417018.png)
4
+ ![image説明](c1bc72f355772f95aa4bb75f8cf0f43c.png)

1

修正

2016/05/04 14:30

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,4 +1,4 @@
1
- 等幅フォントに変更してみてください。
1
+ ラベルのフォントを等幅フォントに変更してみてください。
2
2
 
3
3
  例: Helvetica Regular等...
4
4
  ![image](36b059c6b8ffae7ec1e5394250417018.png)