开发者

How to adjects cell hight auto

i am fetching data from database into table view in database table some roe contain small amount of data some contain very large amount of data , i am trying

CGFloat t = [text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:19.5]].width; 

CGFloat numberOfLine = t/300 + [arr count] + 3; 

CGFloat hh = [text sizeWithFont:[UIFont 开发者_开发百科fontWithName:@"Helvetica" size:19.5]].height;

CGFloat h = hh * numberOfLine; 

return h; 

this type of logic arr contain the number of \n with in the data store in db , now problem is that some cell which contain small amount of data showing couplet data but with extra free lines up n down .. and where amount of data is very large , its skipping data from the end , and in case of large amount of data there is no space in bottom but having some spaces at top.....


Try using :

[text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

CGFloat t = [[text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] sizeWithFont:[UIFont fontWithName:@"Helvetica" size:19.5]].width;

CGFloat numberOfLine = t/300 + [arr count] + 3;

CGFloat hh = [text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:19.5]].height;

CGFloat h = hh * numberOfLine;  

will truncate white spaces & new line characters at the Beginning & end of your text String.

This works fine for me.. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜