2013-02-19 67 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