2017-06-07 3 views
0

私はしたい内容(画像、タイトル、説明を含む)を表に表示します。 同じためにautolayoutを設定しようとしています。セルの高さに応じて画像が縮小しています。 しかし、私は、元のように画像を表示する(すべての画像が差分である。高さ幅)目的関数Cで計画的オートレイアウトを作成するにはどうすればよいですか?

UIImageView *customImageView; 
     UILabel *customLabel; 


     customImageView = [[UIImageView alloc] init]; 
     customImageView.translatesAutoresizingMaskIntoConstraints = NO; 
     customImageView.tag = indexPath.row + 100; 
     customImageView.translatesAutoresizingMaskIntoConstraints = NO; 
     [cell.contentView addSubview:customImageView]; 

     customLabel = [[UILabel alloc] init]; 
     customLabel.translatesAutoresizingMaskIntoConstraints = NO; 
     customLabel.tag = indexPath.row + 500; 
     customLabel.numberOfLines = 0; 
     customLabel.lineBreakMode = NSLineBreakByWordWrapping; 

     [cell.contentView addSubview:customLabel]; 

     NSDictionary *views = NSDictionaryOfVariableBindings(customImageView, customLabel); 
     [cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[customImageView(160)]-[customLabel]|" options:0 metrics:nil views:views]]; 
     [cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-3-[customImageView]-3-|"     options:0 metrics:nil views:views]]; 
     [cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-3-[customLabel]-3-|"      options:0 metrics:nil views:views]]; 

それは 2.howあるとして、私は、画像を表示することができます1.HOw私はタイトルラベル以下の説明のために別のラベルを追加することができます制約を使って? 解決策を提案したり、これについて私を案内してもらえますか?

+0

チェックこの回答https://stackoverflow.com/a/31651348/3338583 –

+0

@SyedAliSalmanthat答えは私の質問のために有用ではない、これをチェック – sss

+0

https://stackoverflow.com/questions/31651022/howプログラムでレイアウトから制約を作成する –

答えて

0

必要なものはすべてUITableViewAutomaticDimensionです。 ImageViewのサイズは暗黙的です。 ImageViewsは、設定された画像に基づいてサイズを取得します。セルに暗黙的なサイズのコンポーネントが含まれている場合、UITableViewAutomaticDimensionを使用して、imageViewのサイズに基づいてセルのサイズをtableViewに指示できます。

あなたはImageViewのの内容モードがcenter

コードに設定していることを確認します

self.tableView.rowHeight = UITableViewAutomaticDimension 
self.tableView.estimatedRowHeight = 140 

indexPathでの行の高さを記述しないでください:)

O/P:

enter image description here

セルサイズを見てください。イメージに基づいてサイズを自動的に変更する。

EDIT:

のみオートレイアウト制約はImageViewの、細胞に添加言及する忘れセルに定0と、リーディング、上部と下部の制約を後続されます。

enter image description here

関連する問題