开发者

UILabels not showing in subclass of UIView

开发者 https://www.devze.com 2023-04-03 14:34 出处:网络
I have a custom view (subclass of UIView) in which I want to show a UIImageView and several UILabels. The imageView comes asynchronously from FaceBook and the labels get their text from specific metho

I have a custom view (subclass of UIView) in which I want to show a UIImageView and several UILabels. The imageView comes asynchronously from FaceBook and the labels get their text from specific methods. The issue is that even though the imageView is rendered successfully when it arrives the labels are not shown. Let me show you the code

@interface CustomView : UIView {

    UIImageView *imageView;
    UILabel *lbl1;
    UILabel *lbl2;
    UILabel *lbl3;
    UILabel *lbl4;
}

@property(nonatomic,retain) UIImageView *imageView;
@property(nonatomic,retain) UILabel *lbl1;
@property(nonatomic,retain) UILabel *lbl2;
@property(nonatomic,retain) UILabel *lbl3;
@property(nonatomic,retain) UILabel *lbl4;

And the implementation is as follows:

@implementa开发者_StackOverflow中文版tion CustomView

@synthesize imageView;
@synthesize lbl1;
@synthesize lbl2;
@synthesize lbl3;
@synthesize lbl4;

- (id)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame]))
    {
        self.lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(65, 356, 98, 13)];
        self.lbl1.backgroundColor = [UIColor clearColor];
        [self addSubview:self.lbl1];

        self.lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(260, 356, 50, 13)];
        self.lbl2.backgroundColor = [UIColor clearColor];
        [self addSubview:self.lbl2];

        self.lbl3 = [[UILabel alloc] initWithFrame:CGRectMake(65, 374, 92, 13)];
        self.lbl3.backgroundColor = [UIColor clearColor];
        [self addSubview:self.lbl3];

        self.lbl4 = [[UILabel alloc] initWithFrame:CGRectMake(260, 374, 49, 13)];
        self.lbl4.backgroundColor = [UIColor clearColor];
        [self addSubview:self.lbl4];
    }
    return self;
}

Please note that label rectangles are hardcoded for convenience and do not match. A sample for the method to set label text is the following:

- (void)showLbl1:(NSString *)str withFont:(UIFont *)font andColor:(UIColor *)color
{
    self.lbl1.font = font;
    self.lbl1.textColor = [UIColor cyanColor];
    [self.lbl1 setText:str];
}

The image is delivered with a method that runs by performSelectorInBackground and drawn with a method that runs by performSelectorOnMainThread. Finally, the whole view is added by addSubView in the superView.

Thanx in advance


Try drawing the labels borders and see where they are ... Also check the uber leak you have there, you have an alloc init and never release the labels and also using the setter, so you are doing a double alloc init.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号