我有一个自定义的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? 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
}
和模拟器中的结果:
我需要将图像限制在一个块(并在一个圆圈中)以显示如下:
除了是方形图像之外,我需要它们成为圆形。我怎么能这样做?
答案 0 :(得分:0)
您可以使用Cocoapods将此库添加到项目中
platform :ios
pod 'APAvatarImageView'
并将类APAvatarImageView
添加到Storyboard或XIB中的UIImageView,它将自动成为一个圆圈https://github.com/ankurp/APAvatarImageView