UA-17470720-3

Jump to content


Photo
- - - - -

Autoresize not working for SCTextViewCell


  • Please log in to reply
4 replies to this topic

#1 Dominic Pepin

Dominic Pepin

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 3 posts
Reputation: 0
Neutral

Posted 30 January 2012 - 07:12 PM

Hi,

I am using the Sensible TableView an would like to create a cell that list business hours. For example:

Business Hours:
Monday to Friday: 9AM to 9PM
Saturday: 10AM to 5PM
Sunday: Closed

or

Business Hours:
Every Day: 9AM to 5PM

For some reason, I cannot get the SCTextViewCell, SCTableViewCell or SCLabelCell to resize automatically (from 1 line to multiple lines).

Here is the code that I used to test the SCTextViewCell:
SCTextViewCell *businessHoursCell = [SCTextViewCell cellWithText:NSLocalizedString(@"Business Hours", nil)];
	//NSString *str = @"Just one line";
	NSString *str = @"Monday - Friday: 7AM to 9PM nSaturday: 9AM to 5PM nSunday: Closed nChristmas, Easter: ClosednMy Wife's birthday: 9AM to 1PM";
	//NSString *str = _currentLocation.hoursOfOperation;
	businessHoursCell.detailTextLabel.text = str;
	businessHoursCell.autoResize = YES;
	businessHoursCell.detailTextLabel.numberOfLines = 0;
	businessHoursCell.editable = NO;
	businessHoursCell.userInteractionEnabled = NO;
	[detailSection addCell:businessHoursCell];

I did the same for the SCLabelView, but in that case also set the lineBreakMode to WordWrap.

I have attached what the output currently looks like.

Thanks

Dominic

Note: I am using version 2.2.0

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 30 January 2012 - 10:01 PM

Hi Dominic,

The easiest way to have STV create an auto resizing label cell is by creating a custom cell with a single label. I've created a project for you that demonstrates that, please find it attached. Please tell me if you need anything else.

#3 Dominic Pepin

Dominic Pepin

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 3 posts
Reputation: 0
Neutral

Posted 31 January 2012 - 07:26 PM

Thanks, it worked.

Just to add to this post, here are the default positions (frames) of the labels:
- Title: 10,2,280,22
- Subtitle: 10,24,280,18

Here are the default fonts:
- Title: Helvetica Bold, size:18
- Subtitle: Helvetica, size: 14

D

#4 Peter Simmons

Peter Simmons

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 14 posts
Reputation: 2
Good

Posted 21 August 2012 - 08:14 PM

Is it possible to do this with STV3.0 for reused cells in an Array of objects section?

#5 Seth Vanderdrift

Seth Vanderdrift

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 108 posts
Reputation: 20
Excellent

Posted 12 November 2015 - 01:32 PM

Is this still the way to make a autosizing Label Cell in STV 5?

 

I have a SCPropertyDefinition for my field/cell as:

    
    SCPropertyDefinition *fullNameDef = [classDef propertyDefinitionWithName:@"fieldFullName__c"];
    fullNameDef.title = @"Name";
    fullNameDef.existsInEditingMode = NO;
    fullNameDef.type = SCPropertyTypeLabel;
    fullNameDef.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCLabelCell *labelCell = (SCLabelCell *)cell;
        labelCell.label.textAlignment = NSTextAlignmentLeft;
        labelCell.label.numberOfLines = 0;
    };

 

But the number of lines doesn't make it use multiple lines for long names.

 

Thanks






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users