English 中文(简体)
单体字体: 单体扫描器含量高能改变浏览量
原标题:iPhone:How to change rowheight by UILabel s content height
  • 时间:2011-08-18 16:31:23
  •  标签:
  • iphone
  • ios

我想动态地将牢房的排入点(即细胞分光)。

困难在于,通过检查其扼制内容,需要检查其高度。

两个问题:

1- 我如何根据扼制的透镜正确确定统一分类的编号?

2- How can I reflect this UIlabel height to row.height because delegate method heightForRowAtIndexPath is called before the cellForRow method?

我确信,这里有些法典是错误的。

Nsstring st= "very long text...";
CGSize theSize = [st sizeWithFont:font constrainedToSize:CGSizeMake(250.0f, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
CGRect cg = CGRectMake(0.0f, 0.0f, 250.0f, theSize.height); 
UILabel *label=[[UILabel alloc] initWithFrame:cg]; 
label.textAlignment=UITextAlignmentLeft;
label.text=st;
[label setNumberOfLines:10];// this is trouble!! how to set this!?
[cell addSubview:label];
最佳回答

www.un.org/Depts/DGACM/index_french.htm

1- 我如何根据扼制的透镜正确确定统一分类的编号?

_OfLines/a>。 “取消任何最高限额,并根据需要使用尽可能多的线,将这种财产的价值确定到0”。

2- 我怎么能反映这种“不知”的高度,以代表的方法高高高。 ForRowAtIndexPath is calls before the cellForRowmeth?

你们需要执行<条码>,以便:,并回到适当的高度。 您可将<代码>Size的计算方法移至助手法,并使用cellForRowAtIndexPath:

问题回答
- (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath {

CGSize labelSize = CGSizeMake(200.0, 20.0);
if ([string length] > 0)
labelSize = [string sizeWithFont: [UIFont boldSystemFontOfSize: 17.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap];
return 24.0 + labelSize.height;
}

You need to implement heightForRowAtIndexPath. In my sample code, I returned 24 + the height of the label

You can have a separate textForRow: function that you can both use to set the text of the label, and also to calculate the size of the label (and the cell) in the delegate method (much like you have already done)





相关问题
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, ...

热门标签