2016-10-19 7 views
0

にバブル(セル)をチャットするサブビューを追加します。私はメッセージを送受信できます。私は<em>アレックスbarinovの</em>チャットバブルの例を使用しています<strong>チャットアプリケーション</strong>に取り組んでいますiOSの

-(void)setupInternalDataという名前のメソッドでUIBubbleTableViewCell.mクラスのチャットバブルのcontentViewにいくつかのラベルを追加しようとしましたが、ラベル(dateラベル)がバブルごとに繰り返され、前のラベルが上書きされ、両方のラベルが含まれます。ここで

は私がプロジェクトをダウンロードした場所からのアドレスである - https://github.com/AlexBarinov/UIBubbleTableView以下

はバブルビューをチャットにラベルを追加するための私のコードです -

-(void)setupInternalData{ 

_fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.origin.x, self.frame.size.height-28, 100, 14)]; 
    _fromLabel.numberOfLines = 1; 
    _fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; 
    _fromLabel.clipsToBounds = YES; 
    _fromLabel.layer.cornerRadius=5; 
    [_fromLabel setFont:[UIFont systemFontOfSize:5]]; 
    [self.customView addSubview:_fromLabel]; 



    //display msg sent time 
    NSDate *today = [NSDate date]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; 
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; 
    NSString *currentTime = [dateFormatter stringFromDate:today]; 
    _lblMsgTime.text=currentTime; 


    _lblMsgTime.frame=CGRectMake(12,0, 85, 14); 
    _lblMsgTime.text=[NSString stringWithFormat:@"%@",currentTime]; 
    _lblMsgTime.textAlignment = NSTextAlignmentRight; 
    _lblMsgTime.textColor = [UIColor blackColor]; 

    [_fromLabel addSubview:_lblMsgTime]; 
    [_lblMsgTime setAdjustsFontSizeToFitWidth:YES]; 

    //date formater 
    NSDate *date = [NSDate date]; 
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    formatter.dateFormat = @"d.M.yyyy"; 
    [formatter setTimeStyle:NSDateFormatterShortStyle]; 
    [formatter setDateStyle:NSDateFormatterMediumStyle]; 
    NSString *string = [formatter stringFromDate:date]; 
    _lblMsgdate.text=string; 


    _lblMsgdate.frame=CGRectMake(60 ,0, 85, 14); 
    _lblMsgdate.text=[NSString stringWithFormat:@"%@",string]; 
    _lblMsgdate.textAlignment = NSTextAlignmentRight; 
    _lblMsgdate.textColor = [UIColor blackColor]; 

    [_fromLabel addSubview:_lblMsgdate]; 
    [_lblMsgdate setAdjustsFontSizeToFitWidth:YES]; 


    UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic__typ__txt.png"]]; 
    backgroundView.frame=CGRectMake(self.frame.origin.x+1, self.frame.size.height-24, 10, 10); 
    [self.customView addSubview:backgroundView]; 
    [self.customView bringSubviewToFront:_fromLabel]; 
    [self.customView bringSubviewToFront:backgroundView]; 
    [self.contentView addSubview:self.customView]; 
} 

誰もが間違っている私がここでやっているものを私に教えてくださいすることができ私は何をしているのですか?どんな助けもありがとうございます。あなたの貴重な答えを待っています。

+0

別々のメソッドではなく、初期化子からサブビューを追加して追加し、別の場所から呼び出します。 –

+0

@ Rohan Bhale - 私はiOSを初めて使っているので、これについて詳しく説明してください。上記のコードを正確に追加する場所お願いします。 –

+0

https://github.com/jessesquires/JSQMessagesViewController –

答えて

0

ねえ、私はあなたがビューを作成し、それを渡す必要があると思います。

あなたはカスタムビューでUILabel *ラベルを交換したいuilable、uiimageを追加し、このビューでは、ビューを作成する必要があり、この中NSBubbleDataファイルの

- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type 
{ 
    UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; 
    CGSize size = [(text ? text : @"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:NSLineBreakByWordWrapping]; 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; 
    label.numberOfLines = 0; 
    label.lineBreakMode = NSLineBreakByWordWrapping; 
    label.text = (text ? text : @""); 
    label.font = font; 
    label.backgroundColor = [UIColor clearColor]; 

#if !__has_feature(objc_arc) 
    [label autorelease]; 
#endif 

    UIEdgeInsets insets = (type == BubbleTypeMine ? textInsetsMine : textInsetsSomeone); 
    return [self initWithView:label date:date type:type insets:insets]; 
} 

でビューを作成します。

+0

提案に感謝します。 –

関連する問題

 関連する問題