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.
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.
UICollectionViewCell is wrong width with label
Open Storyboard
and select your CollectionView
.
Now open Size inspector and change Estimated size Automatic
to None
.
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,
add an UIImageView to your collectionViewCell
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
Swift Update Label (With HTML Content) Takes 1Min
Get the Accurate Duration of a Video
Adding Local Dependencies in Xcode11 Using Spm
Can the Conversion of a String to Data with Utf-8 Encoding Ever Fail
Argument Labels Do Not Match Any Available Overloads
Convert Generic Free Function into Array Extension
How to Use Alamofire with Custom Headers for Post Request
Back Button Image - What Is It Called in Swift
Using Stringbyreplacingcharactersinrange in Swift
Create Nsmanagedobject Subclass... Make a New Error in My Project
How to Handle Closure Recursivity
How to Remove Optional from String Value Swift