I have an restaurant menu iPad app developed for iOS 7 which uses a collectionView
that scrolls horizontally in landscape mode. Menu Section header look like below:
And that's how the xib file looks like for the section header view:
I know it looks weird because the label is horizontal but I'm rotating the label so the label's text becomes vertical bottom to top.
//Rotate the sectionHeader label
[sectionHeader.headerLabel setTransform:CGAffineTransformMakeRotation(-M_PI/2)];
Now the problem is that after updating to iOS9 the label doesn't show at all in the section header view:
Here is my code for the section header:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
//UICollectionReusableView *reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
SectionHeader *sectionHeader = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyHeaderID" forIndexPath:indexPath];
//Load the Menu Sections from the menuSections Array
MenuSection *menuSection = [[MenuSection alloc] init];
menuSection = [self.menuSections objectAtIndex:indexPath.section];
//Rotate the sectionHeader label
[sectionHeader.headerLabel setTransform:CGAffineTransformMakeRotation(-M_PI/2)];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LanguageArabic"] == NO)
{
sectionHeader.headerLabel.text = [NSString stringWithFormat:@"%@", menuSection.sectionName];
}
else
{
sectionHeader.headerLabel.text = [NSString stringWithFormat:@"%@", menuSection.sectionNameArabic];
}
return sectionHeader;
}
When I comment the "Rotate section header" line above and fix the label in the xib file to be vertical and matching the size of the section header view I get the following which is a problem because the label's text should be read vertically bottom to top like the 1st screen shot:
Lastly, I'm using a stickyHeaderFlowLayout by Todd Laney to make the section headers sticky.
Why is that happening with iOS9 and how can I fix it? Thanks
When you apply a rotation transform it rotates the view around it's center point. What you need to do is in your xib file set the constraints for the label to pin it to the center of it's super view vertically and horizontally. And then of course you still apply rotation transform in your code. That should fix the problem.