Welcome, Guest
Username Password: Remember me

textAlignment for an SCTableViewCell - what am I doing wrong?
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: textAlignment for an SCTableViewCell - what am I doing wrong?

textAlignment for an SCTableViewCell - what am I doing wrong? 1 year, 5 months ago #1

Can't get the textAlignment to work, it always looks like UITextAlignmentLeft, regardless of my settings.
I want to make it centered.


 
SCTableViewCell *newCaptchaCell = [SCTableViewCell cellWithText:LocalizedString(@"NewCaptchaButton")];
newCaptchaCell.textLabel.textAlignment = UITextAlignmentRight;
newCaptchaCell.textLabel.textColor = [UIColor redColor];
[section2 addCell:newCaptchaCell];
 


textColor works.

I also tried this

 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel willConfigureCell:(SCTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textAlignment = UITextAlignmentCenter;
}
 


no difference...

But this works for plain UITableViewCells.

Any help is greatly appreciated.
  • steipete
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Karma: 0

Re: textAlignment for an SCTableViewCell - what am I doing wrong? 1 year, 5 months ago #2

What's happening is that STV has resized the cell's textLabel to exactly fit its text contents (required to properly add other controls to the cell). In our next release (beta just announced here: www.sensiblecocoa.com/forum/announcement...0-beta-released.html), you will be able to modify the frame of textLabel (and any other cell control). I can give you a working version in about a week from now. Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: textAlignment for an SCTableViewCell - what am I doing wrong? 1 year, 5 months ago #3

ah... i figured sth like that.
there should be a plain cell, that can be messed with, without adaptions to their internals.
i tried to add a plain UITableViewCell, but that obviously doesn't work.

but if 2.0 will fix that, I can wait. text alignment it's not a blocker
  • steipete
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Karma: 0

Re: textAlignment for an SCTableViewCell - what am I doing wrong? 1 year, 5 months ago #4

Hi Peter,

We've added a new SCTableViewDelegate method called didLayoutSubviews to our new beta 2 release (will send you the release right away). Implementing the new method allows you to set the frame of any of the cell's subviews, including the textLabel we're discussing in this post. Please tell me if you're having any more issues with this.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: textAlignment for an SCTableViewCell - what am I doing wrong? 1 year, 5 months ago #5

thanks, i got it working with beta2.

a strange issue remains. contentView is just larger tan the actual cell, if te cell is grouped.
for now, i added a hack for the width; but there has to be a correct way?


- (void)tableViewModel:(SCTableViewModel *)tableViewModel didLayoutSubviewsForCell:(SCTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (cell.textLabel.textAlignment == UITextAlignmentCenter) {
cell.textLabel.width = cell.contentView.width - 20; // TODO: constant is a hack! what to do on iPad?
}
}
  • steipete
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Karma: 0

Re: textAlignment for an SCTableViewCell - what am I doing wrong? 1 year, 5 months ago #6

Hi Peter,

On the iPhone in portrait mode, for a cell with no accessories, contentView.frame.size.width should return 300 in a grouped table view, and 320 in a plain table view. I am not sure how contentView is giving you values larger than the actual cell. Are you able share some code that will enable me to replicate this? (or possibly send us a test project to our support email) Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
Last Edit: 1 year, 5 months ago by tarekskr.
  • Page:
  • 1
Time to create page: 0.91 seconds