2013-06-17 6 views
-7

enter image description hereОтображение меток с различным цветом фона в сгруппированном столеView?

Привет, друзья. Мне нужно отобразить метки в UItableView. Как я могу это сделать. Просьба сослаться на скриншот.

+4

В чем вопрос? –

+2

и где именно проблема при реализации этого tableView? Наличие ярлыков в UITableViewCell является одним из самых простых вещей, которые вы можете сделать в iOS. –

+0

@ManojEllappan Показать какой-нибудь код пожалуйста. – madLokesh

ответ

3

Вы можете использовать стиль 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; 
} 
1
- (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;   

} 
+0

ok frnd .. и мне нужно вставить две метки в раздел, т. Е. Метку «email» и другую метку, чтобы сохранить ее значение. Поэтому должны быть разные секции для каждой пары значений ярлыка? как вставить эту пару метки-метки в каждый раздел. – Mano

1

UITableViewCell объекты имеют свойство contentView. Добавьте любые пользовательские представления как subviews из contentView. Что вы хотите, это Custom UITableViewCell. Если вы Google для этого, вы найдете много учебников и информации.

Например:

  1. Custom UITableViewCell in IB.
  2. Custom UITableViewCell Using Interface Builder.
Смежные вопросы