Search code examples
objective-cios6.1

How do I integrate PaintCode snippets into XCode (iOS 6)


I need to integrate PaintCode snippets into XCode, but so far I don't see the result in the simulator, here is the snippet for a rectangle:

// Rounded Rectangle Drawing
UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(45.5, 89.5, 232, 273) cornerRadius:3];
[[UIColor whiteColor] setFill];
[roundedRectanglePath fill];
[[UIColor blackColor] setStroke];
[roundedRectanglePath setLineWidth: 10];
[roundedRectanglePath stroke];

I used a void function in implementation file:

- (void) drawRect: (CGRect)rect
{
    // snippet goes here
}

Solution

  • The PaintCode generated code needs to be wrapped in the drawRect: method of a UIView subclass.

    You should also:

    Import your subclass header file in the UIViewController that you seem to be working with, i.e. #import "OnScreenGraphics.h"

    Create an instance of the class, e.g.

    // add a subview to fill the entire view; your requirements
    // may be different, of course
    OnScreenGraphics *fancyView = [[OnScreenGraphics alloc] initWithFrame:self.view.bounds];
    [[self view] addSubview:fancyView];
    

    Edit 2013-11-24 07-33-25

    #import <UIKit/UIKit.h>
    
    @interface OnScreenGraphics : UIView
    
    @end
    
    #import "OnScreenGraphics.h"
    
    @implementation OnScreenGraphics
    
    - (id)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if( !self ) return nil;
    
        self.backgroundColor = [UIColor clearColor];
    
        return self;
    }
    
    - (void)drawRect:(CGRect)rect{
        UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(45.5, 89.5, 232, 273) cornerRadius:3];
        [[UIColor clearColor] setFill];
        [roundedRectanglePath fill];
        [[UIColor blackColor] setStroke];
        [roundedRectanglePath setLineWidth: 10];
        [roundedRectanglePath stroke];
    }
    
    @end
    
    And in your view controller implementation:
    
    @implementation AKDMoreDetailViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        OnScreenGraphics *fancyView = [[OnScreenGraphics alloc] initWithFrame:self.view.bounds];
        [[self view] addSubview:fancyView];
    
    }
    
    // etc.
    
    @end
    

    When I execute this in a test project, I see:

    rectangle-image

    Now, all of this said, your highlighting subview is presumably covering the button you wish to highlight; so even if you can see the button, it may not respond to touch events unless you disable user interaction on that view fancyView.userInteractionEnabled = NO;