Uicollectionviewlayout Not Working with Uiimage in Swift 5 and Xcode 11

UICollectionViewLayout Not working with UIImage in Swift 5 and Xcode 11

Please try this solution. I think there are some changes from Xcode 11.
Change the CollectionView Estimate Size to None then it will work.

Please select your storyboard file

Constrains for ImageView is not working

After researching a bit I have came up with the following way to solved this issue of AutoLayout with UICollectionViewCell. From Xcode 6 CollectionViewCell doesn't show the contentView in interface builder, so in the awakeFromNib of cell I have set its autoresizingMask and it works like charm.

class CustomCell: UICollectionViewCell {
@IBOutlet
var imageView: UIImageView!

override func awakeFromNib() {
super.awakeFromNib()
//Below line solved my problem
self.contentView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
}
}

Image not showing in collectionView

Just add this function

func NKPlaceholderImage(image:UIImage?, imageView:UIImageView?,imgUrl:String,compate:@escaping (UIImage?) -> Void){

if image != nil && imageView != nil {
imageView!.image = image!
}

var urlcatch = imgUrl.replacingOccurrences(of: "/", with: "#")
let documentpath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
urlcatch = documentpath + "/" + "\(urlcatch)"

let image = UIImage(contentsOfFile:urlcatch)
if image != nil && imageView != nil
{
imageView!.image = image!
compate(image)

}else{

if let url = URL(string: imgUrl){

DispatchQueue.global(qos: .background).async {
() -> Void in
let imgdata = NSData(contentsOf: url)
DispatchQueue.main.async {
() -> Void in
imgdata?.write(toFile: urlcatch, atomically: true)
let image = UIImage(contentsOfFile:urlcatch)
compate(image)
if image != nil {
if imageView != nil {
imageView!.image = image!
}
}
}
}
}
}
}

Just Replace

cell.myImage.image = UIImage(named: AllImage[indexPath.row])

with

// Here imgPicture = your imageView
// UIImage(named: "placeholder") is Display image brfore download and load actual image.

NKPlaceholderImage(image: UIImage(named: "placeholder"), imageView: cell.myImage, imgUrl: AllImage[indexPath.row]) { (image) in }

This one is your first image of an array.

Sample Image

UICollectionViewCell is wrong width with label

Open Storyboard and select your CollectionView.

Now open Size inspector and change Estimated size Automatic to None.

Sample Image

Hope this will work.

Swift 5 - Unable to get images to populate from Array

In your initializer you need to do the following:

Remove the static value you assigned to the self.image.
Assign your image argument to self.image (thus making it dynamic)...

You can set your argument's default value so that if no argument is entered in the initialization call you automatically use the "#imageLiteral(resourceName: "blank_whiteTile_48pt")"...

What's happening right now is you have the value hardcoded.

init(title: String, 
image: UIImage = #imageLiteral(resourceName: "blank_whiteTile_48pt"),
display: String) {
self.title = title
self.image = image
self.display = display

}

UIImage Scale Aspect Fill and Clip Subviews not working in UICollectionView

It is very simple just do this:

imageView.contentMode = UIViewContentMode.ScaleAspectFill;
imageView.layer.masksToBounds = YES;

IOS: UICollectionView not showing full images in cells

cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[imagearray objectAtIndex:indexPath.row]]];

will repeat the imageView and you can't see the correct image .
if your want to show an image view at your collection view cell,

  1. add an UIImageView to your collectionViewCell

  2. you can set image this UIImageView at CellForItem ->

    cell.imageview.image =[UIImage imageNamed :@"image name"];
    cell.imageview.contentMode = UIViewContentModeScaleAspectFit;

if I didn't understand the question plz explain more.



Related Topics



Leave a reply



Submit