IBInspectable Default Value im Attribute Inspector

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • IBInspectable Default Value im Attribute Inspector

    Hallo zusammen,

    ich baue mir gerade eine eigene Ansicht und nutze dazu ein UIView. Jetzt habe ich mir eine eigene Klasse erstellt.

    C-Quellcode: ProgressBar.h

    1. #import <UIKit/UIKit.h>
    2. IB_DESIGNABLE
    3. @interface ProgressBar : UIView
    4. @property (nonatomic, strong) NSDictionary *attributes;
    5. @property (nonatomic, copy) IBInspectable UIColor *progressBackgroundColor;
    6. @property (nonatomic, copy) IBInspectable UIColor *progressBarBackgroundColor;
    7. @property (nonatomic, assign) IBInspectable BOOL showPercent;
    8. @property (nonatomic, assign) IBInspectable NSUInteger labelFontSize;
    9. @property (nonatomic, assign) IBInspectable CGFloat progress;
    10. @property (nonatomic, assign) IBInspectable NSUInteger progressLineWidth;
    Alles anzeigen

    C-Quellcode: ProgressBar.m

    1. - (instancetype)initWithFrame:(CGRect)frame {
    2. self = [super initWithFrame:frame];
    3. if (self != nil) {
    4. [self setDefaultValues];
    5. }
    6. return self;
    7. }
    8. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
    9. self = [super initWithCoder:aDecoder];
    10. if (self != nil) {
    11. [self setDefaultValues];
    12. }
    13. return self;
    14. }
    15. /* ... */
    16. -(void)setDefaultValues {
    17. // To set the default colors
    18. [self setProgressBackgroundColor:[UIColor whiteColor]];
    19. [self setProgressBarBackgroundColor:[UIColor whiteColor]];
    20. // To set the default values
    21. [self setProgress:1.0];
    22. [self setProgressLineWidth:10];
    23. [self setLabelFontSize:42];
    24. [self setShowPercent:YES];
    25. }
    26. /* ... */
    27. -(void)setProgress:(CGFloat)progress {
    28. if ((progress >= 0.0) && (progress <= 1.0)) {
    29. _progress = progress;
    30. }
    31. }
    32. -(void)setProgressLineWidth:(NSUInteger)progressLineWidth {
    33. if ((progressLineWidth) && (progressLineWidth <= 100)) {
    34. _progressLineWidth = progressLineWidth;
    35. }
    36. }
    37. -(void)setLabelFontSize:(NSUInteger)labelFontSize {
    38. _labelFontSize = labelFontSize;
    39. }
    40. -(void)setShowPercent:(BOOL)showPercent {
    41. _showPercent = showPercent;
    42. }
    Alles anzeigen
    Ich habe gleiche mehrere Probleme :

    1. Leider werden die Werte Progress, ProgressLineWidth und LabelFontSize aus der Methode setDefaults nicht im Attribute Inspector angezeigt. Was fehlt hier noch ?
    2. Ich kann leider keine Default Hintergrundfarbe für das UIView festlegen. Wie muss ich das machen ?
    3. Wie kann ich die Werte Progress, ProgressLineWidth entsprechend begrenzen im Attribute Inspector ?
    Derzeit sieht mein Attribute Inspector so wie im Anhang.
    Screenshot 2018-09-08 um 15.04.20.png