ios – 带有包装标签的静态表格单元的动态高度?

ios – 带有包装标签的静态表格单元的动态高度?,第1张

概述我的文字在纵向模式下是两行.当我切换到横向模式时,它适合单行.我通过故事板使用静态tableview单元格;我怎样才能调整行的大小以适应? 屏幕是一个登录屏幕. >第一个单元格包含一些解释文本 >第二个是用于输入帐户名称的文本字段 >第三个是用于输入密码的安全文本字段 >第四个(也是最后一个)单元格包含登录按钮.键盘上的返回键提交表单或根据需要切换焦点 使用UITableView的heightFo 我的文字在纵向模式下是两行.当我切换到横向模式时,它适合单行.我通过故事板使用静态tablevIEw单元格;我怎样才能调整行的大小以适应?

屏幕是一个登录屏幕.

>第一个单元格包含一些解释文本
>第二个是用于输入帐户名称的文本字段
>第三个是用于输入密码的安全文本字段
>第四个(也是最后一个)单元格包含登录按钮.键盘上的返回键提交表单或根据需要切换焦点

解决方法 使用UItableVIEw的heightForRowAtIndexPath:
- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath {   int toppadding = 10;   int bottompadding = 10;   float landscapeWIDth = 400;   float portraitWIDth = 300;   UIFont *Font = [UIFont FontWithname:@"Arial" size:22];   //This is for first cell only if you want for all then remove below condition   if (indexPath.row == 0) // for cell with dynamic height   {      Nsstring *strText = [[arrTexts objectAtIndex:indexPath.row]; // filling text in label       if(landscape)//depends on orIEntation     {       CGSize maximumSize = CGSizeMake(landscapeWIDth,MAXfloat); // change wIDth and height to your requirement     }     else //protrait     {       CGSize maximumSize = CGSizeMake(portraitWIDth,MAXfloat); // change wIDth and height to your requirement     }     //dynamic height of string depending on given wIDth to fit     CGSize textSize = CGSizeZero;     if(SYstem_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")     {        NSMutableParagraphStyle *pstyle = [NSMutableParagraphStyle new];        pstyle.lineBreakMode = NSlineBreakByWorDWrapPing;        textSize = [[strText boundingRectWithSize:CGSizeMake(wIDth,MAXfloat) options:NsstringDrawingUseslineFragmentOrigin attributes:@{NSFontAttributename :Font,NSParagraphStyleAttributename:[pstyle copy]} context:nil] size];     }     else // < (iOS 7.0)     {        textSize = [strText sizeWithFont:Font constrainedToSize:maximumSize lineBreakMode:NSlineBreakByWorDWrapPing]      }     return (toppadding+textSize.height+bottompadding) // caculate on your bases as u have string height   }   else   {       // return height from the storyboard       return [super tableVIEw:tableVIEw heightForRowAtIndexPath:indexPath];   } }

编辑:添加支持>和<在iOS 7.0中不推荐使用ios7和sizeWithFont方法

总结

以上是内存溢出为你收集整理的ios – 带有包装标签的静态表格单元的动态高度?全部内容,希望文章能够帮你解决ios – 带有包装标签的静态表格单元的动态高度?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1108445.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存