Pathetic Learner
Pathetic Learner

Reputation: 729

Custom view with UIcontrols elements

i have created a custom view class which is a subclass of UIview class

 @interface CustomViewController : UIView

and i am using drawRect method to display the contents of the custom view

-(void) drawRect(CGRect) rect {

}

I am able to display only strings on custom view but i want to add UITextField and UILabelField and UIButton on the custom view how can i do this. Please help me solve this problem

Upvotes: 2

Views: 134

Answers (1)

Maulik
Maulik

Reputation: 19418

you can put your controls in init... method of your custom view.

EDIT

- (id)initWithFrame:(CGRect)frame 
{    
    self = [super initWithFrame:frame];
    if (self) 
    {
       messageLabel.frame = CGRectMake(10, 20, innerView.frame.size.width-20, 100);
       messageLabel = [messageLabel getSize:messageText FontName:@"Helvetica" FontSize:16 label:messageLabel];
       messageLabel.textColor = [UIColor blackColor];
       messageLabel.textAlignment = UITextAlignmentCenter;
       messageLabel.backgroundColor = [UIColor clearColor];
       messageLabel.frame = CGRectMake(10, 40, innerView.frame.size.width-20,messageLabel.frame.size.height );
       [self addSubview:messageLabel];
    }
    return self;
}

Upvotes: 3

Related Questions