Я начинаю с быстрым, и я не могу получить изменение размера UIImageView.Как изменить размер UIImageView (swift)
Вот мой текущий макет:
То, что я хочу, чтобы изменить размер изображения, чтобы занять половину ширины способность экрана (2 изображения в строке).
Вот моя Раскадровка:
Здесь функция рисования представления коллекции внутри моего контроллера:
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
var cell : MenuInspirationCellView = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as MenuInspirationCellView
cell.imageView.layer.borderWidth = 2
cell.imageView.layer.borderColor = UIColor.yellowColor().CGColor
//This is my first approach trying to modify the frame :
cell.imageView.frame = CGRectMake(0,0, self.view.bounds.width/2,v120)
var cellImage : UIImage = UIImage(data: NSData(contentsOfURL: NSURL(string: images[indexPath.row])))
cell.imageView.image = cellImage;
//This is my second approach (based on http://www.snip2code.com/Snippet/89236/Resize-Image-in-iOS-Swift) :
// to resize an image to dimension 52x52
//var newSize:CGSize = CGSize(width: 52,height: 52)
//let rect = CGRectMake(0,0, newSize.width, newSize.height)
//UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
// image is a variable of type UIImage
//cellImage.drawInRect(rect)
//let newImage = UIGraphicsGetImageFromCurrentImageContext()
//UIGraphicsEndImageContext()
// resized image is stored in constant newImage
//cell.imageView.image = newImage;
//This is my thrid approach (based on https://gist.github.com/hcatlin/180e81cd961573e3c54d, of course i added his functions but I don't show them here for the sake of readability) :
//cell.imageView.image = self.RBSquareImageTo(cellImage, size: CGSize(width: 80, height: 80))
return cell
}
зацепки, чтобы разобраться в этом?
Спасибо! Теперь я могу динамически изменять размеры своих ячеек. Но как изменить размер изображения внутри каждой ячейки? –
Без проблем, @AlexandreNucera. Изображение внутри каждой ячейки можно изменить, отредактировав различные ограничения автоопределения в вашем xib или в коде, установив свойство 'autoresizingMask'' UIImageView '' или вручную сделав макет в '' layoutSubviews' MenuInspirationCellView''. – stefandouganhyde
Спасибо, это именно то, что мне нужно. Я получил эту работу, изменив мои ограничения (я удалил фиксированную ширину и высоту 120). –