Custom View drawRect method is not invoked when use with AutoLayout
Custom View drawRect method is not invoked when use with AutoLayout
- Subject: Custom View drawRect method is not invoked when use with AutoLayout
- From: Sasikumar JP <email@hidden>
- Date: Wed, 16 Jan 2013 21:47:52 +0530
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