Dhaval Parmar
Dhaval Parmar

Reputation: 18978

ios - Uilabel & UIimageview in Uitableviewcell

I want this below type of layout in iPhone (using UItableview, Uitableviewcell, Uilabel and Uiimageview).

enter image description here

(assume light blue dots == uiimageview)

In each UItableviewcell I have 1 UIimageview and 1 Uilabel. both control's starting alightment are same TOP LEFT. My uilabel's content are dynamic and image is only one static image.

Image is very small compare to uilabel's content. So, my image goes center vertical and horizontally. but I want only on TOP Left corner.

Edited :

I have already do this in Uitableviewcell

But if Uilabel have number of line is 2 or more then imageview's position is changed. It goes in center vertically and horizontally. but I want imageview only on top left position whether uilabel's number of line 1,2,3....n

my code is here:

    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;

}

}

In RootViewController.m file

 - (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"];

    }

    }

help me, Thanks in advance.

Upvotes: 1

Views: 843

Answers (2)

Mohit Mehta
Mohit Mehta

Reputation: 1285

Have you set autosizing for the CustomCell View same as given in the image below? Only top and left should be enabled.

enter image description here

Upvotes: 0

Nitin Gohel
Nitin Gohel

Reputation: 49730

  • Create UITableView with Section and grouped style.
  • Your loarem Ipsm (text) set as a Section Title.
  • and Create UITableViewCell custom cell with UIImageView and UILabel to display text "loarem Ipsm is simple dummy"

Upvotes: 3

Related Questions