Is it possible to add custom UIView with autolayout to iCarousel?
If I try to set constraints when custom view is created in iCarousel delegate method
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
app crashed because constraints can be added when view is added to superview but at this point it isn't.
I have new xib for custom view. Problem is that my custom view is too large to fit in iCarousel on iPhone, I don't have problem with arranging views in my custom view but I have problem to fit my custom view in iCarousel because I don't know where to set constraints as I sad constraints can't be set in "viewForItemAtIndex" because view doesn't have superview at that point
You should try adding constraints to the iCarousel view not for viewForItemAtIndex. If the components inside your view needs constraints you may need to create the view in a new xib file with constraints and invoke that view in viewForItemAtIndex method. I came across the same problem and solved it this way.
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
CTProductDetailsInMapView *productView;
if (view == Nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CTProductDetailsInMapView" owner:self options:nil];
productView = (CTProductDetailsInMapView *) [nib objectAtIndex:0];
}
else
productView = (CTProductDetailsInMapView *)view;
}
return productView
}
CTProductDetailsInMapView is a subclass of UIView implemented in an interface file. Here all the components are given constraints and works properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With