Windows や Viewsのガイドなどの Apple ドキュメントを読んでも、これを理解しようとしています。
私の問題は、次のスクリーン キャプチャで最もよく説明されています。
ご覧のとおり、ブログ投稿には高さが可変の (ただし幅は 320px に固定) 画像があり、その下にあるラベルであるビュー要素と重なる場合と重ならない場合があります。
CSS で行うことと同様に、UIImageView を「display:block」とラベルにする必要があります。
したがって、画像が多かれ少なかれ垂直方向のスペースを占める場合、下の要素はそれに応じてその位置を調整します。これはプログラムでのみ行われますか?
それぞれを別々のビューに配置して、これを階層的に実行しようとしましたが、役に立ちませんでした。「サブビューをクリップ」のチェックを外します。
これを行うための一般的な手順に関するアドバイス、または関連資料へのリンクは大歓迎です。
コントローラーコード (postTextLabel と postPicture は IBOutlets に接続されています)
#import "DetailViewController.h"
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController;
@synthesize scroller;
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
CGRect label_frame = CGRectMake(postTextLabel.frame.origin.x,
postPicture.frame.origin.y + postPicture.frame.size.height,
postTextLabel.frame.size.width,
postTextLabel.frame.size.height);
postTextLabel.frame = label_frame;
}
- (void)configureView
{
if (self.detailItem) {
NSDictionary *post = self.detailItem;
NSString *postText = [post objectForKey:@"post_text"];
NSString *postAuthorName = [post objectForKey:@"post_author_name"];
postTextLabel.numberOfLines = 0;
postTextLabel.text = postText;
postAuthorNameLabel.text = postAuthorName;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *pictureUrl = [post objectForKey:@"post_picture"];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:pictureUrl]];
dispatch_async(dispatch_get_main_queue(), ^{
postPicture.image = [UIImage imageWithData:data];
});
});
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end