UITableView的文本,既右对齐和缩进文本、右对齐、UITableView

2023-09-11 07:55:42 作者:什么都不想想起就这样

我要拍一部的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标签帧位置。我在 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.