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.
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.
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.
精彩评论