I've created header using UICollectionViewComposotionalLayout like below
//header
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(30))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: "header", alignment: .top)
section.boundarySupplementaryItems = [header]
and works fine but without any reason when I change the language of the app. all the view changes it's location from left to right using this func :
UIView.appearance().semanticContentAttribute = .forceRightToLeft
except the collectionView header
so I've to trigger it by language and I updated the code to : ▼ but it didn't work
let headerTrailing = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: "header", alignment: .topTrailing)
let headerLeading = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: "header", alignment: .topLeading)
if AppLocalization.currentAppleLanguage() == "en" {
section.boundarySupplementaryItems = [headerLeading]
} else {
section.boundarySupplementaryItems = [headerTrailing]
}
so I've tried to set the textAlignment of the header label in viewForSupplementaryElementOfKind func like below ▼ but it didn't work :
view.headerLabel.textAlignment = .natural
also tried to set it to natural in it's viewCell ▼ but it didn't work :
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
headerLabel.textAlignment = .natural
}
and I also tried this extension to it also ▼ but it didn't work :
extension UILabel {
open override func awakeFromNib() {
super.awakeFromNib()
if AppLocalization.currentAppleLanguage() == "ar" {
if textAlignment == .natural {
self.textAlignment = .right
}
}
}
}
so what should I do to make the header change it's location every time I change the language of the app without relaunching the app again !!?