Note that there are some explanatory texts on larger screens.

plurals
  1. POTableCell image corruption
    primarykey
    data
    text
    <p>I've been working on a little project of mien recently and trying to use this TableView I found on GitHub: <a href="https://github.com/nicolasgomollon/NGDynamicGradientCell" rel="nofollow">https://github.com/nicolasgomollon/NGDynamicGradientCell</a></p> <p>Unfortunately I'm not able to make it work as you can see on this Git: <a href="https://github.com/aout/TestForCells" rel="nofollow">https://github.com/aout/TestForCells</a></p> <p>It seems something is terribly wrong with the way I use it and particularly with the images. Without images everything works fine but when I add them I can't create any cells.</p> <p>here's a bit of code:</p> <pre><code>- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code [self setSelectionStyle:UITableViewCellSelectionStyleNone]; [self setBackgroundColor:[UIColor whiteColor]]; maskFill = [UIImage imageNamed:@"mask-fill.png"]; maskFill = [maskFill resizableImageWithCapInsets:UIEdgeInsetsMake(1.0f, 1.0f, 1.0f, 1.0f)]; bubbleImage = [UIImage imageNamed:@"bubble-min.png"]; bubbleMaskImage = [UIImage imageNamed:@"mask-bubble-min.png"]; bubbleEdgeInsetsSent = UIEdgeInsetsMake(17.0f, 20.0f, 17.0f, 26.0f); bubbleEdgeInsetsReceived = UIEdgeInsetsMake(17.0f, 26.0f, 17.0f, 20.0f); bubbleMaskImage = [bubbleMaskImage resizableImageWithCapInsets:bubbleEdgeInsetsSent]; grayView = [[UIImageView alloc] initWithFrame:CGRectZero]; [grayView setBackgroundColor:[UIColor clearColor]]; [grayView setTintColor:RGBA(229.0f, 229.0f, 234.0f, 1.0f)]; [grayView setAlpha:0.0f]; [self.contentView addSubview:grayView]; messageLabel = [[UILabel alloc] initWithFrame:CGRectZero]; [messageLabel setBackgroundColor:[UIColor clearColor]]; [messageLabel setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]]; [messageLabel setLineBreakMode:NSLineBreakByWordWrapping]; [messageLabel setNumberOfLines:0]; [self.contentView addSubview:messageLabel]; } return self; } + (CGFloat)heightForMessage:(NSString *)message { UIFont *messageFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; CGSize messageConstraints = CGSizeMake(190.0f, MAXFLOAT); CGSize messageSize = [message boundingRectWithSize:messageConstraints options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : messageFont } context:nil].size; CGFloat messageHeight = MAX(35.0f, 10.0f + roundf(messageSize.height) + 5.0f); return messageHeight + kMessagePadding; } - (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { UIGraphicsBeginImageContextWithOptions(newSize, NO, image.scale); [image drawInRect:CGRectSetSize(CGRectZero, newSize)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } - (void)drawRect:(CGRect)rect { [super drawRect:rect]; [messageLabel setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]]; [messageLabel setTextColor:self.sent?[UIColor whiteColor]:[UIColor blackColor]]; CGSize messageConstraints = CGSizeMake(190.0f, MAXFLOAT); CGSize messageSize = [messageLabel.text boundingRectWithSize:messageConstraints options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : messageLabel.font} context:nil].size; CGFloat originX = 18.0f + kBubbleEdgeInset; if (self.sent) originX = self.bounds.size.width - messageSize.width - originX; [messageLabel setFrame:CGRectMake(originX, 7.0f, messageSize.width, messageSize.height)]; CGFloat messageWidth = MAX(48.0f, 13.0f + roundf(messageSize.width) + 18.0f); CGFloat messageHeight = MAX(35.0f, 10.0f + roundf(messageSize.height) + 5.0f); if (self.sent) { UIImage *maskImage = [self imageWithImage:bubbleMaskImage scaledToSize:CGSizeMake(messageWidth, messageHeight)]; UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0f); // Draw the bubble mask image. [maskImage drawInRect:CGRectMake(self.bounds.size.width - messageWidth - kBubbleEdgeInset, 0.0f, messageWidth, messageHeight)]; // Draw the message label text (since it'll be masked out). [messageLabel.text drawInRect:messageLabel.frame withAttributes:@{NSFontAttributeName : messageLabel.font, NSForegroundColorAttributeName : messageLabel.textColor}]; // Draw the mask fill image to the left of the bubble mask image. [maskFill drawInRect:CGRectMake(0.0f, 0.0f, self.bounds.size.width - messageWidth - kBubbleEdgeInset, self.bounds.size.height)]; // Draw the mask fill image to the right of the bubble mask image. [maskFill drawInRect:CGRectMake(self.bounds.size.width - kBubbleEdgeInset, 0.0f, kBubbleEdgeInset, self.bounds.size.height)]; // Draw the mask fill image in the remaining space below the bubble mask image. [maskFill drawInRect:CGRectMake(0.0f, messageHeight, self.bounds.size.width, self.bounds.size.height - messageHeight)]; // Get everything we drew as an image that we can use to mask the cell with. UIImage *imageMask = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); CALayer *maskLayer = [CALayer layer]; [maskLayer setContents:(id)imageMask.CGImage]; [maskLayer setFrame:self.bounds]; [self.layer setMask:maskLayer]; } else { [grayView setFrame:CGRectMake(kBubbleEdgeInset, 0.0f, messageWidth, messageHeight)]; UIImage *maskImage = bubbleImage; maskImage = [UIImage imageWithCGImage:maskImage.CGImage scale:maskImage.scale orientation:UIImageOrientationUpMirrored]; maskImage = [maskImage resizableImageWithCapInsets:bubbleEdgeInsetsReceived]; maskImage = [self imageWithImage:maskImage scaledToSize:CGSizeMake(messageWidth, messageHeight)]; maskImage = [maskImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [grayView setImage:maskImage]; } [messageLabel setAlpha:!self.sent]; [grayView setAlpha:!self.sent]; } - (UILabel *)textLabel { return messageLabel; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end </code></pre> <p>Any Help? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload