UITableView的文本,既右对齐和缩进 [英] UITableView with text that is both right-aligned and indented

查看:183
本文介绍了UITableView的文本,既右对齐和缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要拍一部的UITableView 用,既右对齐和缩进如下图中所描述的文字:

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 

可以这样做使用的UITableView 的属性?如果不是这样,我能想到的唯一的办法就是使用 [myString的drawInRect:withFont:] ,但我想通过进入之前根据对齐和缩进方法 [我已经写了code为:-)] 的,所以其他的变通方法,欢迎!

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!

其他信息:压痕加速度计值的变化,所以我不能有硬codeD标签帧位置。我在<一个上传的样本code href="https://github.com/aakash272/Dynamic-information-display-on-touch-screen-phones/tree/master/floatingList/floatingList"相对=nofollow> github上中,我只用了对齐和缩进的信息,到目前为止,所以继续使用,将使它更容易些。

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.

推荐答案

子类的UITableViewCell 键,就可以定位架。在如果语句,你 dequeueReusableCellWithIdentifier:,其中一个可重复使用的单元不存在,​​只是修改,然后设置标签使用调整后的帧的setFrame 。该自动调整大小面具应保持不变。

Subclass UITableViewCell and you can position the frame of the text label however you like. In the if statement where you dequeueReusableCellWithIdentifier: where a reusable cell doesn't exist, just modify the frame and then set the label to use the adjusted frame with setFrame. The autoresizing mask should remain the same.

这篇关于UITableView的文本,既右对齐和缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆