Ios 自定义表格视图单元格图像失真
我有一个自定义的UITableViewCell,我也有一个图像,但是图像的拉伸非常不寻常。代码如下:Ios 自定义表格视图单元格图像失真,ios,uitableview,swift,Ios,Uitableview,Swift,我有一个自定义的UITableViewCell,我也有一个图像,但是图像的拉伸非常不寻常。代码如下: var count = 0 var propic: NSString = "" var name: NSString = "" for data in listDataArray { if(indexPath.row == count) { if let pic = data["profile_pic"] as? NSStr
var count = 0
var propic: NSString = ""
var name: NSString = ""
for data in listDataArray {
if(indexPath.row == count) {
if let pic = data["profile_pic"] as? NSString {
propic = pic
}
if let n = data["full_name"] as? NSString {
name = n
}
}
count++
}
let decodedData = NSData(base64EncodedString: propic, options: NSDataBase64DecodingOptions(0))
var decodedimage = UIImage(data: decodedData!)
var cell:TableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as? TableViewCell
if (cell == nil)
{
let nib:Array = NSBundle.mainBundle().loadNibNamed("TableViewCell", owner: self, options: nil)
cell = nib[0] as? TableViewCell
}
cell!.nameLabel!.text = name
cell!.imageView!.image = decodedimage
cell!.imageView!.layer.cornerRadius = cell!.recipeImageView!.frame.size.width / 2
cell!.imageView!.layer.borderWidth = 5.0
cell!.imageView!.clipsToBounds = true
cell!.imageView!.layer.borderColor = UIColor(red: 128/225.0, green: 188/225.0, blue: 163/225.0, alpha: 0.45).CGColor;
return cell;
这是.xib
以及TableViewCell.swift
文件:
@IBOutlet var imageView : UIImageView? = UIImageView(frame: CGRectMake(10, 10, 50, 50))
@IBOutlet var nameLabel : UILabel?
@IBOutlet var timeLabel : UILabel?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
以及模拟器中的结果:
我需要将图像限制在一个块(和一个圆圈)内,以如下方式显示:
除了正方形的图像,我需要它们是圆形的。我如何才能做到这一点?您可以使用Cocoapods将此库添加到您的项目中
平台:ios
pod“APAvatarImageView”
然后将类
APAvatarImageView
添加到故事板或XIB中的UIImageView中,它将自动成为一个圆形是否使用自动布局?如果是,imageView上的约束条件是什么?@Tom我没有使用自动布局将图像裁剪为圆形,您可以在此处阅读如何:。此外,要查看代码中的问题,我需要更多的洞察力。你能把你的代码(一部分)寄给我吗?你指的是手机!。recipeImageView!在你发布的代码中我看不到。