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

質問編集履歴

4

画像の追加

2018/11/07 22:31

投稿

reeeeet
reeeeet

スコア95

title CHANGED
File without changes
body CHANGED
@@ -4,7 +4,7 @@
4
4
  ## 問題
5
5
  ** [UIlabelの高さを自動で調整](https://qiita.com/marusy/items/b17eeb72550db5da3fa9)しつつ、[KILabel](https://github.com/Krelborn/KILabel) を使うと UILabel が半分で切れる**
6
6
 
7
- ![イメージ説明](8ea61e8fa733ecb1ab541f1364934049.png)
7
+ ![あああ](8ea61e8fa733ecb1ab541f1364934049.png)
8
8
 
9
9
 
10
10
  ## やりたいこと
@@ -93,4 +93,8 @@
93
93
  postImageView.sd_setImage(with: photoUrl)
94
94
  }
95
95
  }
96
- ```
96
+ ```
97
+
98
+ ***
99
+ **高さ制約を挿入したら解決しました**
100
+ ![イメージ説明](0f8a7302a35bd329eba1d6ff85195563.png)

3

文章を修正

2018/11/07 22:31

投稿

reeeeet
reeeeet

スコア95

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
  ## やりたいこと
11
- labelの高さを自動で調整しつつ、KILabelを使いたい (途中で切れないように)
11
+ [UIlabelの高さを自動で調整](https://qiita.com/marusy/items/b17eeb72550db5da3fa9)しつつ、[KILabel](https://github.com/Krelborn/KILabel) を使いたい (途中で切れないように)
12
12
 
13
13
 
14
14
  ## 試したこと

2

文章の追加

2018/11/07 10:34

投稿

reeeeet
reeeeet

スコア95

title CHANGED
File without changes
body CHANGED
@@ -36,4 +36,61 @@
36
36
  Swift 3.0
37
37
 
38
38
 
39
- すみませんが、よろしくお願いします。
39
+ すみませんが、よろしくお願いします。
40
+
41
+
42
+ ## code
43
+ viewController
44
+ ```Swift
45
+ var post = Post()
46
+ var user = User()
47
+
48
+ @IBOutlet weak var tableView: UITableView!
49
+ override func viewDidLoad() {
50
+ super.viewDidLoad()
51
+ tableView.estimatedRowHeight = 521
52
+ tableView.rowHeight = UITableViewAutomaticDimension
53
+ tableView.separatorStyle = .none
54
+ tableView.dataSource = self
55
+ }
56
+
57
+ extension DetailViewController: UITableViewDataSource {
58
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
59
+ return 1
60
+ }
61
+
62
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
63
+ let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell", for: indexPath) as! HomeTableViewCell
64
+ cell.post = post
65
+ cell.user = user
66
+ cell.delegate = self
67
+ return cell
68
+ }
69
+ }
70
+ ```
71
+
72
+ view (HomeTableViewCell)
73
+ ```Swift
74
+ @IBOutlet weak var captionLabel: KILabel!
75
+
76
+ var post: Post? {
77
+ didSet {
78
+ updateView()
79
+ }
80
+ }
81
+
82
+ func updateView() {
83
+ captionLabel.numberOfLines = 0
84
+ captionLabel.lineBreakMode = NSLineBreakMode.byWordWrapping
85
+ captionLabel.sizeToFit()
86
+ captionLabel.text = post?.caption
87
+ captionLabel.hashtagLinkTapHandler = { label, string, range in
88
+ let tag = String(string.dropFirst())
89
+ self.delegate?.goToHashTag(tag: tag)
90
+ }
91
+ if let photoUrlString = post?.photoUrl {
92
+ let photoUrl = URL(string: photoUrlString)
93
+ postImageView.sd_setImage(with: photoUrl)
94
+ }
95
+ }
96
+ ```

1

文章を修正

2018/11/07 10:31

投稿

reeeeet
reeeeet

スコア95

title CHANGED
File without changes
body CHANGED
@@ -14,8 +14,8 @@
14
14
  ## 試したこと
15
15
  | 試したこと | 結果 |
16
16
  | :-- | :--: |
17
- | 高さの自動調整 だけ | 機能する |
17
+ | 高さの自動調整 **だけ** | 機能する |
18
- | KILabel だけ | 機能する |
18
+ | KILabel **だけ** | 機能する |
19
19
  | KILabel と 高さの自動調整|ダメ|
20
20
 
21
21