IOS, an interface constructor error with render classes and IBInspectables?

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 {
// Drawing code
CGFloat l_borderWidth = self.AaBorderWidth; // 8.5
CGFloat l_cornerRadius = self.AaCornerRad; // 33
CGFloat l_shadHeight = self.AaShadHeight; // 15.1
CGFloat l_textYOffset = self.AaTextYOffset; // 6.1

if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact)
{
    if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact)
    {
        //iphone3.5 / 4 / 4.7 landscape
        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)
    {
        //ipad landscape
        l_borderWidth = self.RrBorderWidth;
        l_cornerRadius = self.RrCornerRad;
        l_shadHeight = self.RrShadHeight;
        l_textYOffset = self.RcTextYOffset;
    }
    if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact)
    {
        //iphone6+
        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];
    // Run time, loading from xib.
}

- (void)prepareForInterfaceBuilder
{
    [super prepareForInterfaceBuilder];
    // Design time.
    [self setSizingClassValues];
}
+4
source share
1

, . ? ? , Xcode. , . , , , ? !

0

Source: https://habr.com/ru/post/1615970/


All Articles