多くのラベルに解析されたXMLが埋め込まれたビューがあります。そのビューはUIScrollView内にあります。 XMLの中には、ラベルが長すぎるものがあります。 XMLコンテンツに基づいてラベルのサイズを変更しています。ラベルのサイズが変更されると、UIScrollView内のUIViewのサイズが変更されていないため、ラベルが次のラベルと重なります。私はこれに答えを見つけようと何時間もインターネットを精練してきたが、私が試したことはすべて私が探しているものを達成していない。どんな助けでも大歓迎です。内容に基づいたUIViewのサイズ変更
これは私のpopulateLabelsメソッドです。
-(void) populateLabels {
NSString *noInfo = (@"No Information Available");
lblCgName.text = _Campground.campground;
NSString *cgLoc = _Campground.street1;
NSString *cgCity = _Campground.city;
NSString *cgState = _Campground.state1;
NSString *cgCountry = _Campground.country;
NSString *cgZipPostal = _Campground.zipPostal;
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgCity];
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgState];
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgCountry];
cgLoc = [[cgLoc stringByAppendingString:@" "] stringByAppendingString:cgZipPostal];
lblCgLoc.text = cgLoc;
double dRate = [_Campground.regRate1 doubleValue];
double dRate2 = [_Campground.regRate2 doubleValue];
NSString *rate = [[NSString alloc] initWithFormat:@"$%0.2f",dRate];
NSString *rate2 = [[NSString alloc] initWithFormat:@"$%0.2f",dRate2];
if ([rate2 isEqualToString:@"$0.00"]) {
lblRate.text = rate;
} else {
rate = [[rate stringByAppendingString:@" - "] stringByAppendingString:rate2];
lblRate.text = rate;
}
double dPaRate = [_Campground.paRate1 doubleValue];
double dPaRate2 = [_Campground.paRate2 doubleValue];
NSString *paRate = [[NSString alloc] initWithFormat:@"$%0.2f",dPaRate];
NSString *paRate2 = [[NSString alloc] initWithFormat:@"$%0.2f",dPaRate2];
if ([paRate2 isEqualToString:@"$0.00"]) {
lblPaRate.text = paRate;
} else {
paRate = [[paRate stringByAppendingString:@" - "] stringByAppendingString:paRate2];
lblPaRate.text = paRate;
}
lblLocal1.text = _Campground.localPhone1;
lblLocal2.text = _Campground.localPhone2;
lblTollFree.text = _Campground.tollFree;
lblFax.text = _Campground.fax;
lblEmail.text = _Campground.email;
lblWebsite.text = _Campground.website;
NSString *gps = _Campground.latitude;
NSString *longitude = _Campground.longitude;
gps = [[gps stringByAppendingString:@", "] stringByAppendingString:longitude];
lblGps.text = gps;
lblHighlights.text = _Campground.highlights;
lblHighlights.lineBreakMode = UILineBreakModeWordWrap;
lblHighlights.numberOfLines = 0;
//label resizing
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [_Campground.highlights sizeWithFont:lblHighlights.font
constrainedToSize:maximumLabelSize
lineBreakMode:lblHighlights.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = lblHighlights.frame;
newFrame.size.height = expectedLabelSize.height;
lblHighlights.frame = newFrame;
lblTents.text = _Campground.tents;
lblNotes.text = _Campground.notes;
lblDirections.text = _Campground.directions;
lblRentals.text = _Campground.rentals;
}
http://stackoverflow.com/questions/2998336/how-to-create-a-uiscrollview-programmaticallyこれは、あなたが望む種類のビューを作成するのに役立ちます... – rishi
私は感謝していますそれは私が探しているものではありません。彼らはコードでスクロールビューを作成し、それをサイズ変更しています。私は既に持っているスクロールビュー内に既に持っているビューのサイズを変更するために探しています。すべてがうまくいっていて、全部スクロールします。私は、ラベルが表示されているビューを拡張する必要があります。 – tallybear
最初にすべてのラベルを作成することをお勧めします。この後は、ビューの高さを動的に計算することができます - label_height + offset_height_between_label + header_footer_offset。今、このmchの高さであなたのビューを作成し、そこにラベルを追加することができます。 – rishi