Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pfaucon
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfaucon/6f7c2ba0328ce38cb22b to your computer and use it in GitHub Desktop.
Save pfaucon/6f7c2ba0328ce38cb22b to your computer and use it in GitHub Desktop.
minimum obj-c to reproduce textview issue
-(void)awakeFromNib
{
if(!self.descriptionTextView)
{
self.descriptionTextView = [[UITextView alloc] initWithFrame:self.bounds];
self.descriptionTextView.text = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.";
[self addSubview:self.descriptionTextView];
}
if(!self.moreButton)
{
self.moreButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.moreButton setTitle:kMoreTitle forState:UIControlStateNormal];
[self.moreButton addTarget:self action:@selector(showMore:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.moreButton];
}
[self.moreButton setTitle:kMoreTitle forState:UIControlStateNormal];
self.descriptionTextView.scrollEnabled = NO;
self.descriptionTextView.editable = NO;
self.frame = kDefaultSize;
[self updateTextFrame];
[self updateShowMoreFrame];
}
-(void) updateTextFrame
{
self.descriptionTextView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}
-(void)updateShowMoreFrame
{
self.moreButton.frame = CGRectMake(self.frame.size.width - 100,self.frame.size.height - 30, 100, 30);
}
-(void)layoutSubviews
{
[super layoutSubviews];
[self updateShowMoreFrame];
[self updateTextFrame];
}
- (IBAction)showMore:(id)sender {
if([[self.moreButton titleForState:UIControlStateNormal] isEqualToString:kMoreTitle])
{
[self.descriptionTextView sizeToFit];
CGRect newFrame = self.frame;
newFrame.size.height = self.descriptionTextView.frame.size.height;
self.frame = newFrame;
}
else
{
self.frame = kDefaultSize;
}
[self updateMoreButton];
}
-(void)updateMoreButton
{
if([[self.moreButton titleForState:UIControlStateNormal] isEqualToString:kMoreTitle])
{
[self.moreButton setTitle:kLessTitle forState:UIControlStateNormal];
}
else
{
[self.moreButton setTitle:kMoreTitle forState:UIControlStateNormal];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment