作成中の新しい記事があります。UILabel
記事タイトルにAを追加中です。タイトル テキストは、1 行、2 行、または 3 行のテキストになる場合があります。UILabel
次に、タイトルの下に を作成する必要があります。
UILabel
タイトルの高さが動的であるため、日付の配置に問題があります。
私UILabel
のフレームの下の位置を取得する計算はありますか?
注:のフレームが適合siteToFit
することを確認するために使用しています。UILabel
// Text
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.view.bounds.size.width-20, 50)];
//title.backgroundColor = [UIColor clearColor];
title.backgroundColor = [UIColor redColor];
title.text = self.firstItem.title;
//title.text = @"This is a test of a short title that is a little longer";
title.textColor = [UIColor whiteColor];
title.layer.shadowColor = [UIColor blackColor].CGColor;
title.layer.shadowOffset = CGSizeMake(0, 0);
title.layer.shadowRadius = 0.6;
title.textAlignment = NSTextAlignmentLeft;
title.layer.shadowOpacity = 1.0;
title.layer.masksToBounds = NO;
title.font = [UIFont boldSystemFontOfSize:16.0];
title.numberOfLines = 0;
[title sizeToFit];
[self.firstNewsItemBackgroundView addSubview:title];
self.cachedParalax = self.firstNewsItemBackgroundView.frame;
// Fix positioning
title.center = CGPointMake(title.center.x, self.imageView.frame.size.height - title.frame.size.height);
// Date
UILabel *titleDate = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.view.bounds.size.width-20, 50)];
titleDate.backgroundColor = [UIColor clearColor];
titleDate.text = self.firstItem.publishedDateString;
titleDate.textColor = [UIColor whiteColor];
titleDate.layer.shadowColor = [UIColor blackColor].CGColor;
titleDate.layer.shadowOffset = CGSizeMake(0, 0);
titleDate.layer.shadowRadius = 0.7;
titleDate.textAlignment = NSTextAlignmentLeft;
titleDate.layer.shadowOpacity = 0.95;
titleDate.layer.masksToBounds = NO;
titleDate.font = [UIFont italicSystemFontOfSize:12.0];
titleDate.numberOfLines = 0;
[title sizeToFit];
[self.firstNewsItemBackgroundView addSubview:titleDate];
// Fix positioning
CGRect frame = titleDate.frame;
titleDate.frame = CGRectMake(10, title.center.y + (title.frame.size.height/2), frame.size.width, frame.size.height);