How to load an image in prepareForInterfaceBuilder with a IBDesignable UIImageView

后端 未结 7 2253
迷失自我
迷失自我 2020-12-23 14:27

I would like to load a sample image in an IB designable UIImageView, to be shown in Interface Builder while editing the interface. The following code does not w

7条回答
  •  清酒与你
    2020-12-23 15:20

    This will load your IB_Designable, or if you have none - the default image.

    - (void)prepareForInterfaceBuilder
    {
        NSBundle *bundle = [NSBundle bundleForClass:[self class]];
        imagePic = imagePic ? [imagePic imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] : [UIImage imageNamed:@"goodIcon" inBundle:bundle compatibleWithTraitCollection:self.traitCollection];
    
    }
    

提交回复
热议问题