【问题标题】:Change label and icon positions of tableview's cell更改表格视图单元格的标签和图标位置
【发布时间】:2011-11-20 15:05:44
【问题描述】:

可以改变我的tableview单元格的位置哦图像和标签吗? 我不会使用 CustomCell..

我已经尝试过这个(用于标签)..

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    else
        return cell;

    UIImage *image = nil;

            cell.textLabel.text = @"text label";
            UILabel *label = cell.textLabel; 
            CGRect frame = label.frame;
            frame.origin.x = 62;
            frame.origin.y = 62;
            label.frame = frame;
            image = [UIImage imageNamed:@"icon.png"];


    cell.textLabel.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.imageView.image = image;

    return cell;

}

【问题讨论】:

标签: objective-c uitableview uiimageview uilabel


【解决方案1】:

请取一个 UIview..并给帧大小与单元格大小相同...然后在该视图中添加标签...以及您想要添加的任何内容..在该视图中添加为子视图...而不是添加单元格中的那个视图。

一切顺利

【讨论】:

    【解决方案2】:
    //table cell contains title,date,image
    
            - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
            {
    
    
                   static NSString *CellIdentifier = @"Cell";
    
              UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                cell =nil;
                [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
                if (cell == nil) 
    
                {
                           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
                }
    
           //tittle label     
    
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:contentFrame] ;
                titleLabel.numberOfLines = 2;  
                titleLabel.font = [UIFont boldSystemFontOfSize:12];
                titleLabel.text = [currentTweet title];
                [cell.contentView addSubview:titleLabel];
    
        //date label
    
            UILabel *dateLabel = [[UILabel alloc] initWithFrame:dateFrame];
                dateLabel.font = [UIFont systemFontOfSize:10];
                dateLabel.text = [currentTweet dateCreated];
                [cell.contentView addSubview:dateLabel];
    
        //image view
            CGRect imageFrame = CGRectMake(2, 8, 40,50);    
              self.customImage = [[UIImageView alloc] initWithFrame:imageFrame];
              customImage.image =image;
            [cell.contentView addSubview:self.customImage];
            return cell;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多