tipycalFlow
tipycalFlow

Reputation: 7644

UITableView with text that is both right-aligned and indented

I wanted to make a UITableView with text that is both right-aligned and indented as depicted in the image below:

enter image description here

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.

Upvotes: 2

Views: 1342

Answers (2)

bertusaurus
bertusaurus

Reputation: 634

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.

Upvotes: 0

user244343
user244343

Reputation:

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.

Upvotes: 1

Related Questions