2017-03-15 106 views
0

我附上一个sample project,让您可以测试,看看我能做些什么来解决这个适合标签或图像和圆角。调整大小的UITableViewCell到

我试图动态调整的高度的形象,同时轮两个角上的其他各小区。这样做会导致切断的面罩。

基本上这里就是我想实现:

  1. UITableView中的行高设置为自动。通过使用CustomTableViewCell

    [self.nImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){}]; 
    
  2. 配置细胞圆边角取决于其行

    UIBezierPath *maskPath = [UIBezierPath 
             bezierPathWithRoundedRect:self.bubbleView.bounds 
             byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerTopLeft) 
             cornerRadii:CGSizeMake(20, 20)]; 
    
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
    
    maskLayer.frame = self.bubbleView.bounds; 
    maskLayer.path = maskPath.CGPath; 
    
    self.bubbleView.layer.mask = maskLayer; 
    

做上述结果SDWebImage库

_nTableView.rowHeight = UITableViewAutomaticDimension; 
_nTableView.estimatedRowHeight = 150; 
  • 下载图片掩模是切断但高度计算正确。见下: enter image description here

    基于这个stack overflow's question,我们需要删除掩码,如果有的话。我曾试图设置awakeFromNib方法面膜零但是这并没有影响。

    self.nImageView.layer.mask = nil; 
    self.nImageView.layer.masksToBounds = NO; 
    

    我也尝试过从这个question的答案,但它导致应用程序崩溃。

    预先感谢您。

  • +0

    你保持图像的大小固定或可变的? –

    +0

    抓住您的示例项目...是的,它崩溃,直到我删除cellForRowAtIndexPath中的“删除层”代码...但是,我不能告诉你要做什么。你在这里的照片是你想要的吗?如果不是,它应该怎么看? – DonMag

    +0

    @DonMag我已经使用“图层”代码更新了项目。如果你评论[cell configureBubbleInRow:indexPath.row],你会看到我想看到的。看到这个:http://imgur.com/a/JVtA3 –

    回答

    1

    这里是一个可能的解决方案 - 可能不是最好的,可能不会做的正是你所需要的,但可能让你对你的方式...

    ,而不是试图操纵层/面具从你的内自定义UITableViewCell类,使用UIView子类作为图像的持有者。该类的代码可以处理圆角和图层/蒙版尺寸更新。

    见这里的例子:https://github.com/DonMag/dhImage

    +0

    非常感谢!这使它工作! –

    -1

    要根据设定的行的高度上它的内容:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
        { 
    
        if(/*check if content is text label*/) 
        { 
         UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"]; 
         UILabel *lbl = (UILabel*)[ cell.contentView viewWithTag:1000]; 
         lbl.text = message; 
         [cell layoutIfNeeded]; 
         CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; 
    
         if(size.height < 100) { 
          return 100; 
         } 
         else { 
          return size.height; 
         } 
        } 
        else {     // content is image 
         return 200; 
         } 
        } 
    

    配置圆边角细胞:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        . 
        . 
        . 
        [cell.contentView.layer setCornerRadius:10.0f]; 
        return cell; 
    } 
    

    要下载使用SDWebImage库图片:

     SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader]; 
         [downloader downloadImageWithURL:addr 
               options:0 
               progress: 
            ^(NSInteger receivedSize, NSInteger expectedSize) { 
             // progression tracking code 
               } 
               completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { 
             if (image && finished) { 
              // Pass the imageView to this block 
              // After completion display downloaded image in imageView 
              imageView.image = image; 
             } 
            }]; 
    

    希望能帮助到你!!

    +0

    希望它有帮助!回复@AndyM –

    +0

    由于删除了cellForRowAtIndexPath中的图层,导致系统崩溃,但是您也没有提及无故更改变量名称 – zombie

    +0

    哪部分? @ zombie –

    相关问题