Я работаю над приложением чата, где я использую чата пример пузырьковой AleX Баринова. Я могу отправлять/получать сообщения. Я хочу, чтобы добавить некоторые ярлыки и мнение каждого чат пузырь, как время, дата, произнесенные изображения и т.д.добавления подтаблицы в чат пузыря (сотовый) в прошивкой
Я пытался добавить некоторые ярлыки над contentView в чате пузыря в UIBubbleTableViewCell.m
классе в методе с именем -(void)setupInternalData
, но метка (дата label) повторяется для каждого пузыря, и он перезаписывает предыдущую метку, и в ней содержатся метки.
Вот адрес, откуда я скачал проект - 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];
}
Может кто-нибудь пожалуйста, скажите мне, что не так я делаю здесь , и что я должен делать. Любая помощь приветствуется. Ожидание ваших ценных ответов.
Попробуйте инициализировать и добавить subviews из инициализатора вместо отдельного метода и вызвать его из какого-либо другого. –
@ Rohan Bhale - вы можете подробно рассказать об этом, так как я новичок в iOS. Где точно добавить вышеуказанный код? Пожалуйста. –
https://github.com/jessesquires/JSQMessagesViewController –