UITableView 的文本右对齐且缩进
我想制作一个 UITableView
,其文本既右对齐又缩进,如下图所示:
不幸的是,我无法通过编写以下内容来做到这一点:-
cell.textLabel.textAlignment = UITextAlignmentRight;
cell.indentationLevel = 10; // or even -10
可以使用 UITableView
的属性来完成此操作吗?如果没有,我能想到的唯一方法是使用 [myString drawInRect:withFont:];
但我想在进入该方法之前先了解一下基于对齐和缩进的方法[我有已经为此编写了代码:-)],因此欢迎使用其他解决方法!
其他信息:缩进随加速度计值的变化而变化,因此我不能对标签框架位置进行硬编码。我已在 github ,到目前为止我只使用了对齐和缩进信息,因此继续使用它会让这变得更容易。
I wanted to make a UITableView
with text that is both right-aligned and indented as depicted in the image below:
Unfortunately, I can not do this by writing :-
cell.textLabel.textAlignment = UITextAlignmentRight;
cell.indentationLevel = 10; // or even -10
Can this be done using UITableView
's properties? If not, the only way I could think of is using [myString drawInRect:withFont:];
but I would like to go through methods based on alignment and indentation before getting into that [I have already written code for that :-) ], so other work-arounds are welcome!
Additional info: The indentation varies with accelerometer values so I can not have hard-coded Label frame positions. I've uploaded sample code at github in which I've used only the alignment and indentation info so far, so continuing to use that would make this easier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
子类
UITableViewCell
,您可以根据需要放置文本标签的frame
。在if
语句中dequeueReusableCellWithIdentifier:
如果可重用单元不存在,只需修改frame
,然后设置标签以使用使用setFrame
调整框架。自动调整大小蒙版应保持不变。Subclass
UITableViewCell
and you can position theframe
of the text label however you like. In theif
statement where youdequeueReusableCellWithIdentifier:
where a reusable cell doesn't exist, just modify theframe
and then set the label to use the adjusted frame withsetFrame
. The autoresizing mask should remain the same.您始终可以创建自己的自定义单元格并将 UITextLabel 放置在单元格中,并使 UITextLabel 的对齐方式右对齐。
还将 UITextLabel 的自动调整大小掩码设置为右侧,以便无论方向如何,缩进距离都保持不变。
You could always create your own custom cells and place a UITextLabel in the cell, and make the UITextLabel's alignment right aligned.
Also set the autoresizing mask of the UITextLabel to the right so the indentation distance stays the same no matter the orientation.