Отображение меток с различным цветом фона в сгруппированном столеView?
Привет, друзья. Мне нужно отобразить метки в UItableView. Как я могу это сделать. Просьба сослаться на скриншот.
Отображение меток с различным цветом фона в сгруппированном столеView?
Привет, друзья. Мне нужно отобразить метки в UItableView. Как я могу это сделать. Просьба сослаться на скриншот.
Вы можете использовать стиль UITableViewCell UITableViewCellStyleValue1
. Используйте Custom view для заголовка раздела.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 22.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UILabel *sectionLabel = [[UILabel alloc]initWithFrame:CGRectZero];
sectionLabel.backgroundColor = [UIColor purpleColor];//Choose your color
sectionLabel.textColor = [UIColor whiteColor];
sectionLabel.font = [UIFont boldSystemFontOfSize:17.0f];
sectionLabel.text = @"Section Name";
return sectionLabel;
}
- (UITableViewCell *)tableView:(UITableView *)TableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
//Default detailTextLabel would have blue text color change it to your choice
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
}
cell.textLabel.text = @"Mobile Number";
cell.detailTextLabel.text = @"Type";
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellsToBeReused = @"CellsToBeReused";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellsToBeReused];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellsToBeReused] autorelease];
}
UILabel* Label = [[UILabel alloc] initWithFrame:CGRectMake(2,2, 62, 23)];
[Label setText:@"Text"];
Label.backgroundColor = [UIColor whiteColor];
[cell.contentView addSubview:Label];
[Label release];
return cell;
}
ok frnd .. и мне нужно вставить две метки в раздел, т. Е. Метку «email» и другую метку, чтобы сохранить ее значение. Поэтому должны быть разные секции для каждой пары значений ярлыка? как вставить эту пару метки-метки в каждый раздел. – Mano
UITableViewDelegate имеет метод -
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Вы можете просто вернуть настроенную UILabel
UITableViewCell
объекты имеют свойство contentView
. Добавьте любые пользовательские представления как subviews
из contentView
. Что вы хотите, это Custom UITableViewCell
. Если вы Google для этого, вы найдете много учебников и информации.
Например:
С его помощью вы лучше разбираетесь в UITableView. Apple, является лучшим ресурсом
Надеется, что это помогает !!!
В чем вопрос? –
и где именно проблема при реализации этого tableView? Наличие ярлыков в UITableViewCell является одним из самых простых вещей, которые вы можете сделать в iOS. –
@ManojEllappan Показать какой-нибудь код пожалуйста. – madLokesh