2016-09-08 3 views
1

セル内のテキスト/イメージのサイズを変更しようとしています。しかし、ラベルには、その位置に応じていくつかの丸い角があります。私のようなスニペットを使用して試してみました:ラベルに合うようにセルのサイズを変更し、イメージサイズを設定し、ラベルに丸みのある角がいくつかあります。

let path = UIBezierPath(roundedRect:cell.receivedText!.bounds, byRoundingCorners:[.TopRight, .BottomLeft, .BottomRight], cornerRadii: CGSizeMake(30, 30)) 
    let maskLayer = CAShapeLayer() 
    maskLayer.path = path.CGPath 
    cell.receivedText!.layer.mask = maskLayer 

tableView.estimatedRowHeight = 44 
    tableView.rowHeight = UITableViewAutomaticDimension 

しかし、私は、2つの一緒に仕事を得る傾けます。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    createConversation() 
    let cell: ConversationCell = tableView.dequeueReusableCellWithIdentifier("ConversationCell") as! ConversationCell 

    if conversation.conversationArray[indexPath.row].isAReceivedMessage == true { 
     cell.receivedText!.text = conversation.conversationArray[indexPath.row].text 
     cell.receivedText!.textAlignment = .Left 
     cell.receivedText!.sizeToFit() 
     cell.receivedProfileImage!.image = self.conversationProfileImage!.image 
     cell.receivedText!.backgroundColor = UIColor(red: 44/255, green: 99/255, blue: 105/255, alpha: 5/100) 

    } else { 
     cell.sentText!.text = conversation.conversationArray[indexPath.row].text 
     cell.sentText!.textAlignment = .Right 
     cell.sentText!.backgroundColor = UIColor(red: 204/255, green: 115/255, blue: 115/255, alpha: 1) 
     cell.sentText!.sizeToFit() 
    } 

    return cell 
} 

これは事前に任意の助け

This is what im trying to achieve

感謝を達成しようとするものイムです:

はここで仕事をdidntの私の現在のコードマイナススニペットです。

+0

解決方法を見つけましたか?私は同じ問題にぶつかっています。 –

答えて

0

しかし、私は一緒に働く2つを得ることができません。

  • タイミング:

は二つの問題があります。ビューのサイズを変更すると、マスクのサイズが変更されません。したがって、ビューの最終サイズを知る前にマスクを貼り付けると、誤った答えが得られます。

  • レスキュー。セルが再利用されることを忘れないでください。したがって、cellForRowでは、既存のマスクがあれば削除する必要があります。これは、新しいサイズ変更セルに合わせて別のマスクを作成しようとしているためです。

  • +0

    詳細を教えてください。私はどのように既存のマスクを削除するか分からない。そうすると私にとってはクラッシュにつながる。 –

    +0

    @AndyMご不明な点がございましたら、ご質問ください。 – matt

    +0

    マスクがあれば、どのようにマスクを取り除きますか? –

    関連する問題