2013-02-19 36 views
1

我想在iPhone中使用下面的布局类型(使用UItableView,Uitableviewcell,Uilabel和Uiimageview)。ios - 在Uitableviewcell中的Uilabel和UIimageview

enter image description here

(假设浅蓝色点==的UIImageView

在每种的UITableViewCell我有1周的UIImageView和1的UILabel。 两个控件的起始照明都是相同的左前。 我的uilabel的内容是动态的,图片只是一张静态图片。

与uilabel的内容相比,图像是非常小的。因此,我的图像中心垂直和水平。但我只想在左上角。

编辑:

我已经在Uitableviewcell

为此但是,如果具有的UILabel线的数目为2个或更多的则imageview的立场发生变化。 它垂直和水平中心。但我想只在左上角位置的ImageView线1,2,3的UILabel的数量.... n是否

我的代码是在这里:

In CommonCustomeCell.m 



- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { 

self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]; 


if (self) { 

dotImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dotPoint.png"]]; 

     dotImage.opaque = YES; 

     [self.contentView addSubview:dotImage]; 

    titleName3 = [[UILabel alloc] init]; 

titleName3.textAlignment = UITextAlignmentLeft;  

titleName3.backgroundColor = [UIColor clearColor]; 

     titleName3.adjustsFontSizeToFitWidth = FALSE; 

     titleName3.font = [UIFont systemFontOfSize:14]; 

     titleName3.textColor = [UIColor colorWithRed:17.0/255.0 green:72.0/255.0 blue:147.0/255.0 alpha:1]; 

     titleName3.lineBreakMode = NSLineBreakByWordWrapping;  

     [titleName3 sizeToFit];  

     [self.contentView addSubview:titleName3]; 

} 

-(void)layoutSubviews 

{ 

    frame = CGRectMake(20,2,self.bounds.size.width - 45 , self.bounds.size.height); 

    [titleName3 setFrame:frame]; 

frame = CGRectMake(4,10,dotImage.frame.size.width,dotImage.frame.size.height); 

    self.dotImage.frame = frame; 

} 

} 

在RootViewController.m文件

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

    { 

    CommonCustomeCell *cell = (CommonCustomeCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

       if (cell == nil) {     

        cell = [[[CommonCustomeCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

    } 

    [cell.dotImage5 setImage:[UIImage imageNamed:@"myLogo.png"]]; 

    cell.titleName3.text = [[myArr objectAtIndex:indexPath.row] objectForKey:@"title"]; 

    } 

    } 

帮助我,在此先感谢。

+0

创建自定义“的UITableViewCell”,和地方的ImageView任何你想要的。 – jamapag 2013-02-19 09:04:24

+0

检查我编辑的问题。 – 2013-02-19 09:36:58

+0

你能否在你的自定义单元格中显示创建imageView的代码? – jamapag 2013-02-19 14:23:41

回答

3
  • 创建UITableView部分和分组样式。
  • 您的loarem Ipsm(正文)设置为标题。
  • 和创建UITableViewCellUIImageViewUILabel自定义单元格中显示文本 “loarem IPSM是简单的虚拟”
+0

This if if my Uilabel的行数为2或更多,则imageview的位置发生变化。它垂直和水平地位于中心。但我只需要在左上方的图像视图,不管是第1行还是第2行还是第3行或第4行等等。 – 2013-02-19 09:29:27

0

有如下图中给出您设置自动调整大小的CustomCell取景?只有顶部和左侧应该启用。

enter image description here

+0

请检查我编辑的问题。 – 2013-02-19 09:37:48

+0

@DhavalSodhaParmar我明白你的问题。如果将自定义单元视图自动调整设置为底部以及启用右侧自动调整,则可能会发生这种情况。确保它应该与给定的图像相同。或者你可以设置图像视图的框架。例如[Image setFrame:CGRectMake(0,0,167,37)]; – 2013-02-19 09:42:18

+0

但我没有使用xib文件,只使用自定义类(父类:UITableviewCell)我必须为所有iOS版本制作通用应用程序。 – 2013-02-19 09:49:08

相关问题