• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Custom View drawRect method is not invoked when use with AutoLayout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom View drawRect method is not invoked when use with AutoLayout


  • Subject: Re: Custom View drawRect method is not invoked when use with AutoLayout
  • From: Sasikumar JP <email@hidden>
  • Date: Thu, 17 Jan 2013 14:30:14 +0530

I have rephrased my earlier question to get some experts attention :)

Is there any difference in creating a custom view in interface builder over code.

If I create the custom view from interface builder, drawrect method is getting invoked, if I do it from code,drawrect is not getting invoked?



Thanks
Sasikumar

Sent from my iPhone

On Jan 16, 2013, at 9:47 PM, Sasikumar JP <email@hidden> wrote:

> Hi,
>   I am working on a project, where i have to create horizontal tableview with custom tableview cell. i am using AutoLayout constraints to layout all cell's subview elements.
>
> Here is the my tableview cell init method, here i am using JPFilmBorderView to draw some custom drawing. but JPFilmBorderView drawRect method never gets invoked.
> - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
>
> {
>
>     NSLog(@"initwithstyle invoked");
>
>     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
>
>     if (self) {
>
>         JPFilmBorderView *topFilmBorderView = [[JPFilmBorderView alloc] initWithFrame:CGRectZero];
>
>         topFilmBorderView.contentMode = UIViewContentModeRedraw;
>
>         topFilmBorderView.backgroundColor = [UIColor whiteColor];
>
>         topFilmBorderView.translatesAutoresizingMaskIntoConstraints = NO;
>
>
>
>         JPFilmBorderView *bottomFilmBorderView = [[JPFilmBorderView alloc] initWithFrame:CGRectZero];
>
>         bottomFilmBorderView.translatesAutoresizingMaskIntoConstraints = NO;
>
>         bottomFilmBorderView.backgroundColor = [UIColor greenColor];
>
>
>
>         self.thumbnailImage = [[UIImageView alloc] initWithFrame:CGRectZero];
>
>         _thumbnailImage.translatesAutoresizingMaskIntoConstraints = NO;
>
>
>
>         [self.contentView addSubview:topFilmBorderView];
>
>         [self.contentView addSubview:_thumbnailImage];
>
>         [self.contentView addSubview:bottomFilmBorderView];
>
>
>
>         NSDictionary *viewDict = NSDictionaryOfVariableBindings(_thumbnailImage, topFilmBorderView, bottomFilmBorderView);
>
>         [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topFilmBorderView(20)]-[_thumbnailImage]-[bottomFilmBorderView(20)]|" options:0 metrics:nil views:viewDict]];
>
>         [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[topFilmBorderView]" options:0 metrics:nil views:viewDict]];
>
>         [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_thumbnailImage]" options:0 metrics:nil views:viewDict]];
>
>         [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[bottomFilmBorderView]" options:0 metrics:nil views:viewDict]];
>
>
>
>     }
>
>     return self;
>
> }
>
> Here is the JPFilmBorderView implementation.i never see the NSLog output from drawRect method.
>
> ============================
>
> @implementation JPFilmBorderView
>
> - (id)initWithFrame:(CGRect)frame
>
> {
>
>     self = [super initWithFrame:frame];
>
>     if (self) {
>
>         // Initialization code
>
>     }
>
>     return self;
>
> }
>
> - (void)drawRect:(CGRect)rect
>
> {
>
>     NSLog(@"Rect %@",[NSValue valueWithCGRect:rect]);
>
> }
>
> I am observing this problem only if i define the custom view from program, where as if i use storyboard/nib file, custom view drawRect method is getting invoked.
>
> i am not sure what i am missing here. any help is highly appreciated.
>
> Thank you
>
> Sasikumar JP
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Custom View drawRect method is not invoked when use with AutoLayout (From: Sasikumar JP <email@hidden>)

  • Prev by Date: Re: Changing color in NSColorPanel without message
  • Next by Date: Re: Comparator blocks in NSSortDescriptor not supported in Core Data?
  • Previous by thread: Re: Provisioning profiles
  • Next by thread: book for n00b
  • Index(es):
    • Date
    • Thread