My custom UIView is not triggering this to run, but other custom views I make trigger it. Does anyone know the reason that this automatic refreshing of views would be triggered? Or Why "Refresh All Views" is greyed out.
Code is in here: https://github.com/HannahCarney/HCRotaryWheel
Make sure you have IBInspectable
properties for your view. (like
changing your view color,just to make sure your IBDesignable
thing
works).
Make sure you have the code for your customisation in your view .m
file. (in your view draw rect method).
IBDesignable
view.(in your storyboarD)Make sure you mention IB_DESIGNABLE
on your view .h file.
Finally a qucik clean and build of your storyboard,shall enable the
option of Refresh All views.
Sample code:
for view.h
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface designalble_UIView : UIView
@property (nonatomic) IBInspectable UIColor *startColor;
@property (nonatomic) IBInspectable UIColor *midColor;
@property (nonatomic) IBInspectable UIColor *endColor;
@property (nonatomic) IBInspectable NSInteger borderWidth;
@property (nonatomic) IBInspectable CGFloat cornerRadious;
@property (nonatomic) IBInspectable BOOL isHorizontal;
@end
for view.m
#import "designalble_UIView.h"
@implementation designalble_UIView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.startColor = [UIColor redColor];
self.midColor = [UIColor greenColor];
self.endColor = [UIColor blueColor];
self.borderWidth = 2;
self.cornerRadious = 10;
self.isHorizontal = NO;
[self customInit];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self customInit];
}
return self;
}
- (void)drawRect:(CGRect)rect {
[self customInit];
}
- (void)setNeedsLayout {
[super setNeedsLayout];
[self setNeedsDisplay];
}
- (void)prepareForInterfaceBuilder {
[self customInit];
}
- (void)customInit {
self.layer.cornerRadius = self.cornerRadious;
self.layer.borderWidth = self.borderWidth;
if (self.cornerRadious > 0) {
self.layer.masksToBounds = YES;
}
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[self.startColor CGColor],(id)[self.midColor CGColor], (id)[self.endColor CGColor], nil];
gradient.endPoint = (self.isHorizontal) ? CGPointMake(1, 0) : CGPointMake(0, 1);
[self.layer insertSublayer:gradient atIndex:0];
}
I solved this because I had put IB_DESIGNABLE in the wrong spot in my code:
I had a protocol at the top of my view and previously it looked like
IB_DESIGNABLE
@protocol RotaryProtocol <NSObject>
- (void) wheelDidChangeValue:(int)currentSector;
@end
@interface HCRotaryWheel : UIView
@property (weak) id <RotaryProtocol> delegate;
@property (nonatomic, strong) IBInspectable UIColor* background;
@end
To fix this I had to move IB_DESIGNABLE below protocol
@protocol RotaryProtocol <NSObject>
- (void) wheelDidChangeValue:(int)currentSector;
@end
IB_DESIGNABLE
@interface HCRotaryWheel : UIView
@property (weak) id <RotaryProtocol> delegate;
@property (nonatomic, strong) IBInspectable UIColor* background;
@end
Now my views refresh!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With