1
votes

First, I have a exist Asset.m/Asset.h, it is the subclass of UIView. Then I create a empty xib file and change xib's file's owner class to Asset. Then I create a view and a label to this xib, and I can drag and create IBOutlet in UIView.

IBOutlet UIView *videoOverlay;
IBOutlet UILabel *videoTimeLable;

Then I want to add videoOverlay to Asset.m's view using addSubview.

self = [super initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:videoOverlay];

But the view -- videoOverlay do not show up.

I print out size of videoOverlay, all 0:

    NSLog(@"width =%f height= %f", videoOverlay.frame.size.width, videoOverlay.frame.size.height);

Why ?

1
try [self.view addSubview: videoOverlay] - WaaleedKhan
It seems you have set the size zero, haven't you? CGRectMake(0, 0, 0, 0); :D - holex
YES, But videoOverlay has size in xib file. - kevin young
Asset is a UIView, so there hasn't self.view, itself is a view. - kevin young

1 Answers

0
votes

Finally, I find the solution by myself. Use under code to add this view (videoOverlay and videoTimeLable belong to this view )in:

UIView *thumbs;
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ELCAsset" owner:self options:nil];
    thumbs = [nib objectAtIndex:0];
    [self addSubview:thumbs];

then videoOverlay and videoTimeLable can show up.