I'm not sure what is going on, I am pulling my hair out trying to get around this, I am trying to satisfy various code rendering classes to cater for some special cases using IBInspectables.
In the simulator, the following code works as expected on the iPad, iPhone 4 and iPhone 6+.
However, in the interface designer and preview there is only any / any and regular / regular work.
It seems like a mistake? Or does anyone have suggestions for an alternative approach that might work?
- (void)drawRect:(CGRect)rect {
CGFloat l_borderWidth = self.AaBorderWidth;
CGFloat l_cornerRadius = self.AaCornerRad;
CGFloat l_shadHeight = self.AaShadHeight;
CGFloat l_textYOffset = self.AaTextYOffset;
if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact)
{
if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact)
{
l_borderWidth = self.CcBorderWidth;
l_cornerRadius = self.CcCornerRad;
l_shadHeight = self.CcShadHeight;
l_textYOffset = self.CcTextYOffset;
}
}
if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular)
{
if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassRegular)
{
l_borderWidth = self.RrBorderWidth;
l_cornerRadius = self.RrCornerRad;
l_shadHeight = self.RrShadHeight;
l_textYOffset = self.RcTextYOffset;
}
if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact)
{
l_borderWidth = self.RcBorderWidth;
l_cornerRadius = self.RcCornerRad;
l_shadHeight = self.RcShadHeight;
l_textYOffset = self.RcTextYOffset;
}
}
EDIT: I also tried the following methods
- (void)layoutSubviews
{
[super layoutSubviews];
[self setSizingClassValues];
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
[super traitCollectionDidChange:previousTraitCollection];
[self setSizingClassValues];
}
- (void)updateConstraints
{
[self setSizingClassValues];
[super updateConstraints];
}
.
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
[self setSizingClassValues];
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)prepareForInterfaceBuilder
{
[super prepareForInterfaceBuilder];
[self setSizingClassValues];
}
Jules source
share