Allen
Allen

Reputation: 3771

Loading custom UIView

I have a custom view called RedDot that has this in the .m file:

   - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        return self;
    }

    - (void)drawRect:(CGRect)rect
    {
        //// Color Declarations
        UIColor* fillColor = [UIColor colorWithRed: 0.886 green: 0 blue: 0 alpha: 1];

        //// Oval Drawing
        UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(30, 30, 7, 7)];
        [fillColor setFill];
        [ovalPath fill];
        [fillColor setStroke];
        ovalPath.lineWidth = 1;
        [ovalPath stroke];
    }

I'm trying to call it in the main view with this code, but its not working:

RedDot *dot = [[RedDot alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 30.0f, 30.0f)];
[self.view addSubview:dot];

Edit:

it just shows a black rectangle in the corner.

Upvotes: 0

Views: 56

Answers (1)

Vladimir
Vladimir

Reputation: 170849

You create your bezier path you want to draw outside view's bounds:

UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(30, 30, 7, 7)];

Create bigger view or change rect for your circle and you should see your drawing then.

Upvotes: 2

Related Questions