I have a UICollectionReusableView for a UICollectionView Header Section in code as follows:
var headingLabel: UILabel! override init(frame: CGRect) { super.init(frame: frame) headingLabel = UILabel(frame: CGRectMake(12.0,12.0,frame.width,21.0)) headingLabel.numberOfLines = 1 headingLabel.textAlignment = NSTextAlignment.Center headingLabel.textColor = UIColor.blackColor() self.backgroundColor = UIColor.whiteColor() self.addSubview(headingLabel) }
I just want the heading to be centered in the display. This is fine so long as I don't rotate the device. If I rotate the device, the label is no longer in the center of the screen.
My guess is this is super simple, I just can't seem to find the answer. My assumption is that I could just programatically add constraints, but I can't quite work out how to do that.
Alternatively, I think there might be some way to force it to redo the headers on a layout change, but I couldn't get that working either.
Any pointers in the right direction would be hugely appreciated.
Many thanks.