2016-10-08 10 views
-1

画像を使用できる場合は設定できましたが、何らかの理由で画像のサイズを画像ビューに設定できません。少なくとも切り抜きプレビュー)私はthisUITableViewCellでUIImageViewの画像サイズを設定できません

の線に沿って何かをしようとしたしかし、あなたが見ることができるように、画像はここで、なぜ... enter image description here

は、レイアウトがどのように見えるかだと確信していない細胞全体を取って終わります...私はアスペクトフィルのために行こうとした...しかし、最終結果はほぼ同じになる...

enter image description here

編集:コードを追加しました。追加するのを忘れました。

func getLocalComments(point:PFGeoPoint){ 
    var temp = [CommentDetails]() 
    DispatchQueue.global(qos: .background).async { 
     let qComments = PFQuery(className: "UserCommentary") 
     let qDrinks = PFQuery(className: "venueDrinks") 
     if self.type == "House Parties"{ 
      //Query the bars 
      qDrinks.whereKey("venueName", equalTo: self.id) 
      qDrinks.whereKey("venueID", equalTo: self.venueName) 
      qDrinks.addDescendingOrder("createdAt") 

      qComments.whereKey("venueID", equalTo: self.id) 
      qComments.whereKey("venueName", equalTo: self.venueName) 

      do{ 

       let qReply1 = try qDrinks.findObjects() 
       if qReply1.count>0{ 
        let comment:CommentDetails = CommentDetails.init(comm: "Test", ven: self.venueName, venId: self.id, owner: PFUser.current()!.username!, vote: 0) 
        var i = 0 
        while i < 2 { 
         let item = qReply1[i] 
         print(item) 
         comment.cellType = 2 
         i+=1 
        } 
        //temp.append(comment) 
       } 
       let qReply2 = try qComments.findObjects() 
       for item in qReply2{ 
        let comment:CommentDetails = CommentDetails.init(comm: "Test", ven: self.venueName, venId: self.id, owner: PFUser.current()!.username!, vote: 0) 
        comment.commentOwner = item.object(forKey: "owner") as! String 
        comment.comment = item.object(forKey: "comment") as! String 
        comment.isFile = item.object(forKey: "image") as! Bool 

        if comment.isFile { 
         let dataPhoto:PFFile = item.object(forKey: "imgFile") as! PFFile 
         let imageData:NSData = try dataPhoto.getData() 
         let image:UIImage = UIImage(data:imageData as Data)! 
         comment.imageFile = image 
         comment.cellType = 2 
        } 
        temp.append(comment) 
       } 
      } 
      catch{ 
       print(error) 
      } 
     } 

     DispatchQueue.main.async { 
      print(temp) 
      self.commentList.removeAll() 
      self.commentList = temp 
      self.commentTableView.reloadData() 

     } 

    } 


} 

答えて

0

ここで行う2つのものがあります:tabeview細胞

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell{ 
    var cell:commentTableViewCell 
    if commentList[indexPath.row].cellType == 1{ 
     //drink 
     cell = self.commentTableView.dequeueReusableCell(withIdentifier: "drink",for: indexPath) as! commentTableViewCell 
     cell.drinkName.text = commentList[indexPath.row].commentOwner 
     cell.drinkPrice.text = commentList[indexPath.row].comment 

     return cell 
    } 
    else{ 
     //comment 
     cell = self.commentTableView.dequeueReusableCell(withIdentifier: "comment",for: indexPath) as! commentTableViewCell 
     cell.ownerTitle.text = commentList[indexPath.row].commentOwner 
     cell.commentContent.text = commentList[indexPath.row].comment 
     if commentList[indexPath.row].isFile{ 
      //cell.imageView!.contentMode = UIViewContentMode.scaleAspectFill 
      cell.imageView!.image = commentList[indexPath.row].imageFile 
     } 
     else if !commentList[indexPath.row].isFile { 
      cell.imageView!.image = nil 
      cell.imageView!.removeFromSuperview() 

     } 
     return cell 
    } 
} 

parsequeryを設定

  • は、画像ビューのclipsToBoundstrueに設定します。さもなければ、画像ビューがどれほど小さくても、の外側にある画像の部分がの外側に表示されます。

  • 画像の幅と高さを判断するのに十分な制約があります。さもなければ、それはイメージのサイズであることを試みます。

+0

イメージをアスペクトフィールにしたいのでイメージを塗りつぶしますが、イメージは完全に表示されません。 –

+1

アスペクトフィッティングは、画像を完全に表示します(「フィット」)。 – matt

+0

ああ、画像がイメージビューに収まるようにする方法はありますか?申し訳ありませんが、これは少し混乱しているようです。イメージビューの基準を満たすようにイメージをサイズ変更する必要がありますか? –

関連する問題