English 中文(简体)
根据内容重新编写《统一意见》
原标题:Resizing UIView based on content

我有多种标签,如XML。 这一观点符合美国国际法学会的意见。 某些XML对标签来说太长了。 I m 重塑基于XML内容的标签。 当贴上标签时,这些标签重复了后面的标签,因为我的《国际数据集》(即《国际数据集》)的字眼没有重新编号。 我在数小时时间里一直鼓励互联网,试图找到答案,但我所尝试的一切都没有达到我所期望的目标。 任何帮助都将受到高度赞赏。

This is my populateLabels method.

-(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;

}
最佳回答

位于何地的<条码>-(避免)活胎/代码>方法? 如果看着控制员的话,你就应该容易地了解需要重新调整的观点。 另一种做法是,如果在需要调整的观念中添加标签(期望已经建立)的话,那么你可以查阅他们的超级看法。 你们已经满足了你们的需要,只是确定了方法结束时的超视距范围。

如果你试图首先根据扼杀内容找到每个标签的大小,你就希望采用国家抽样调查方法: -sizeWithFont。 这有几个不同之处,使你能够具体说明制约因素:

Computing Metrics for a Single Line of Text – sizeWithFont: – sizeWithFont:forWidth:lineBreakMode: – sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: Computing Metrics for Multiple Lines of Text – sizeWithFont:constrainedToSize: – sizeWithFont:constrainedToSize:lineBreakMode:

仅凭单显示1行。 还铭记这将恢复护堤将占用的规模。 公民和公民自由联盟 意见倾向于增加婚礼,因此,在计算最高点时,你可能需要说明这一点。 在你计算了高点并贴上了每个标签之后,你应当知道超级电文必须达到的大小,并适当确定。 而且,如果你不知道什么标签是最后的/最低的/最坏的(超级意见的大小应是原产地。 您可以这样做:

CGFloat totalHeight = 0.0f;
for (UIView *view in superView.subviews)
    if (totalHeight < view.frame.origin.y + view.frame.size.height) totalHeight = view.frame.origin.y + view.frame.size.height;

如果你已经知道,这将给你高望(如果需要,你也可以做同样的事)。

问题回答

Do you really need to use a bunch of labels?
It seems you need to use UITextView or UIScrollView.

The general method to resize a UIView based on its subviews is sizeToFit This method resizes your UIView automatically.

If you wanted to constrain the size, you ll need to use sizeThatFits: This method does not resize your UIView automatically, rather it returns the size.

仅附带说明: 这两种方法只是次调查中的因素,因此无法绘画或核心文本。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签