UITableView with text that is both right-aligned and indented

喜夏-厌秋 提交于 2019-12-10 23:18:01

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7683196/uitableview-with-text-that-is-both-right-aligned-and-indented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!