auto-sizing UICollectionView in UITableView with pure code - ios

I am trying to create one UITableView with header and UITableViewCell header is fixed size. and in each UITableViewCell I will create one UICollectionView. the UICollectionViewCell height is not fixed. so Here I want UICollectionViewCell is auto-sizing in UICollectionView and UICollectionView is auto-sizing in UITableViewCell.
But The height is not auto-sizing after implementation. Could you help me on this.
TableView init:
- (UITableView *)tableView
{
if (_tableView == nil) {
CGFloat top = 20;
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
_tableView.delegate = self;
_tableView.separatorStyle = 0;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = 200;
_tableView.sectionHeaderHeight = 40;
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.backgroundColor = [UIColor whiteColor];
}
return _tableView;
}
UICollectionView in UITableViewCell Init:
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.bounces = NO;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.translatesAutoresizingMaskIntoConstraints = NO;
[_collectionView registerClass:[KCollectionViewCell class] forCellWithReuseIdentifier:#"KCollectionViewCell"];
[self.contentView addSubview:_collectionView];
[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.contentView);
make.left.equalTo(self.contentView).offset(20);
make.right.equalTo(self.contentView).offset(-20);
}];
UICollectionViewCell init:
-(void)initUI{
self.label = [[UILabel alloc] init];
self.label.text = #"aaaaaaaaaaaaaaaa";
self.label.textColor = XUIColorMain;
self.label.textAlignment = NSTextAlignmentCenter;
self.label.layer.borderColor =[UIColor orangeColor].CGColor;
self.label.clipsToBounds = YES;
[self.label sizeToFit];
}
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
UICollectionViewLayoutAttributes *attributes = [super preferredLayoutAttributesFittingAttributes:layoutAttributes];
CGRect frame = [self.label.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.label.font,NSFontAttributeName, nil] context:nil];
frame.size.width += 10;
frame.size.height = 30;
attributes.frame = frame;
return attributes;
}

Related

How to create UITableView programmatically

I have the following code to create a view with a table programmatically
- (void) createView:(UIViewController*)viewController{
_thisViewController = viewController;
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = #"Title";
titleLabel.frame = CGRectMake(75, 20, 200, 50);
titleLabel.textColor = [UIColor blackColor];
titleLabel.font = [titleLabel.font fontWithSize: 24];
UILabel *subtitleLabel = [[UILabel alloc] init];
subtitleLabel.text = #"Subtitle";
subtitleLabel.frame = CGRectMake(75, 50, 400, 50);
subtitleLabel.textColor = [UIColor blackColor];
subtitleLabel.font = [subtitleLabel.font fontWithSize: 20];
UILabel *labelStatus = [[UILabel alloc] init];
labelStatus.text = #"";
labelStatus.frame = CGRectMake(75, screenHeight - 290, 500, 50);
labelStatus.textColor = [UIColor blueColor];
labelStatus.font = [labelStatus.font fontWithSize: 20];
UITableView *tableDeviceList = [[UITableView alloc] init];
tableDeviceList.frame = CGRectMake(75, 100, screenWidth -250, screenHeight - 400);
tableDeviceList.dataSource = self;
tableDeviceList.delegate = self;
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
[cancelButton setTitle:#"Cancelar" forState:UIControlStateNormal];
[cancelButton sizeToFit];
cancelButton.frame = CGRectMake((screenWidth/2)-100, screenHeight - 250, 100, 50);
cancelButton.backgroundColor = UIColorFromRGB(0x066D8B);
cancelButton.layer.cornerRadius = 20;
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cancelButton addTarget:self action:#selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIViewController *viewControllerModal = [[UIViewController alloc] init];
UIView *nooView = [[UIView alloc] initWithFrame:CGRectMake(50, 80, screenWidth - 100, screenHeight - 160)];
nooView.backgroundColor = UIColorFromRGB(0xE8E8E8);
nooView.layer.cornerRadius = 20;
[nooView addSubview:titleLabel];
[nooView addSubview:subtitleLabel];
[nooView addSubview:tableDeviceList];
[nooView addSubview:labelStatus];
[nooView addSubview:cancelButton];
[viewControllerModal.view addSubview:nooView];
[viewController presentViewController: viewControllerModal animated:YES completion:nil];
}
Which is throwing me an error of tableView:numberOfRowsInSection:, so I wonder if is there a way to add a function to a UITableView created this way (I'm creating my UITableView programmatically).
Also, my class is of type NSObject, so I wonder if there will be a problem with the assignment of the dataSource and delegate properties of the tableDeviceList.
You need to implement the dataSource and delegate methods of UITableView in your class,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; // number of sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10; // should be your array count
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.textlabel.text = #"test";
return cell;
}
Firstly, you should set the following:
UITableView(your tableview name).delegate = self;
UITableView(your tableview name).dataSource = self;
Secondly, you need to implement the delegate methods and datasource methods
such as:

Make UITableViewCell contains a UICollectionView

I got a problem to make uitablveiewcell contains a uicollectionview.The tableview setting is:
_tableViewOfSend = ({
TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor whiteColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.delegate = self;
tableView.dataSource = self;
tableView.estimatedRowHeight = 200;
tableView.rowHeight = UITableViewAutomaticDimension;
[tableView registerClass:[TopicWriteTextCell class] forCellReuseIdentifier:kTextCell];
[tableView registerClass:[TopicWriteImageCell class] forCellReuseIdentifier:kImageCell];
[self.view addSubview:tableView];
tableView;
});
and I added some constraints:
[_tableViewOfSend autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_navBar withOffset:1];
[_tableViewOfSend autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.view];
[_tableViewOfSend autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.view];
[_tableViewOfSend autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.view];
The tableviewcell also add constrains for self-sizing. In my demo, i just used for presenting images.So i add an UICollectionView in it.
UICollectionViewLeftAlignedLayout *layout = [[UICollectionViewLeftAlignedLayout alloc] init];
layout.minimumLineSpacing = 5;
layout.minimumInteritemSpacing = 5;
CGFloat widthOfScreen = [UIScreen mainScreen].bounds.size.width;
CGFloat cellWidth =(widthOfScreen - 20 - 5 * 2) / 3;
NSLog(#"cell height%f", cellWidth);
layout.itemSize = CGSizeMake(cellWidth, cellWidth);
_imageCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, widthOfScreen, cellWidth*2 + 10) collectionViewLayout:layout];
_imageCollectionView.delegate = self;
_imageCollectionView.dataSource = self;
_imageCollectionView.scrollEnabled = NO;
_imageCollectionView.backgroundColor = [UIColor colorWithRed:0.6 green:1 blue:0.6 alpha:0.5];
[_imageCollectionView registerClass:[TopicWriteImageCCell class] forCellWithReuseIdentifier:kImageCellIndentify];
[self.contentView addSubview:_imageCollectionView];
And the add the constraints for the UICollectionView:
[_imageCollectionView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.contentView];
[_imageCollectionView autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.contentView withOffset:10];
[_imageCollectionView autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.contentView withOffset:-10];
[_imageCollectionView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.contentView];
I just set the itemsize for a fixed value. The UICollectionViewCell only add a ImageView. and also add the left/top/right/bottom constraints. The item number is 5. In my opinion, I have fixed the itemsize, and add all needed constrains, it should be show 5 items with right height. But there is only 3 items, and the height is not right. It seems the cell didn't self-sizing.
Can anyone help?

How to add padding from left right only for label in uitable cell

How to add padding from left right only for label in UITableViewCell?
Here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"cellmessage";
SendMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[SendMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell setAccessoryType:UITableViewCellAccessoryNone];
NSDictionary *dict = [self->serverArray objectAtIndex: indexPath.row];
cell.celllab.text= [dict objectForKey:#"message"];
CGFloat fixedWidth = cell.celllab.frame.size.width;
CGSize newSize = [cell.celllab sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = cell.celllab.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height + 10);
cell.celllab.frame = newFrame;
cell.celllab.layer.cornerRadius = 4.0f;
cell.celllab.layer.masksToBounds = YES;
//cell.celllab.layer.borderColor = [UIColor blackColor].CGColor;
//cell.celllab.layer.borderWidth = 10.0;
CAShapeLayer *shape = [CAShapeLayer layer];
shape.frame = cell.celllab.bounds;
//shape.path = maskPath.CGPath;
shape.lineWidth = 3.0f;
shape.strokeColor = [UIColor whiteColor].CGColor;
[cell.celllab.layer addSublayer:shape];
if([[dict objectForKey:#"type"] isEqualToString:#"u2a"])
{
cell.celllab.textAlignment = NSTextAlignmentRight;
cell.celllab.backgroundColor = [UIColor colorWithRed:0.7 green:0.91 blue:0.26 alpha:1];
cell.celllab.textColor = [UIColor blackColor];
cell.blackarrow.hidden = YES;
cell.greenarrow.hidden = NO;
cell.bmwatch.hidden = YES;
cell.swiliam.hidden = NO;
cell.greenmsg.hidden = NO;
cell.whitemsg.hidden = YES;
}
else
{
cell.celllab.backgroundColor = [UIColor blackColor];
cell.celllab.textColor = [UIColor whiteColor];
cell.celllab.textAlignment = NSTextAlignmentLeft;
cell.greenarrow.hidden = YES;
cell.blackarrow.hidden = NO;
cell.bmwatch.hidden = NO;
cell.swiliam.hidden = YES;
cell.greenmsg.hidden = YES;
cell.whitemsg.hidden = NO;
}
return cell;
}
In your SendMessageTableViewCell class write below function to change the frames of its subviews
- (void)layoutSubviews{
self.textLabel.frame = CGRectMake(rightPadding, topPadding,self.frame.size.width - (2*rightPadding), self.frame.size.height-(2*topPadding))
}
Above code in your custom class will be called when your cell contents subviews changes their frame and at that time you can give padding to your lable and also can change other contents frames.
Its very simple.Just subclass the uilabel and write this method
- (void)drawTextInRect:(CGRect)rect {
UIEdgeInsets insets = {0, 5, 0, 5};
return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}

cellForRowAtIndexPath and sizeToFit reduces label width when scrolling

I've a custom cell with labels init in a UITableViewCell.
In my cellForRowAtIndexPath method after setting label content i call sizeToFit on the label to get the correct width and height, but when i scroll in my TableView, the label width reduce on each cells, every time i scroll.
Anyone for help ?
Thanks
My custom UITableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
CGRect viewBounds = self.contentView.bounds;
// marge
CGFloat margin = 20;
self.excuse_date = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, 300, 30)];
self.excuse_date.textColor = [UIColor blackColor];
self.excuse_date.font = [UIFont fontWithName:#"Arial" size:12.0f];
[self addSubview:self.excuse_date];
static CGFloat dateWidth = 130;
self.excuse_date.frame = CGRectMake(viewBounds.size.width-dateWidth-35, margin, dateWidth, 20);
CGRect dateFrame = self.excuse_date.frame;
self.excuse_date.textAlignment = NSTextAlignmentRight;
// setup excuse_auteur
self.excuse_auteur = [[UILabel alloc] init];
self.excuse_auteur.font = [UIFont fontWithName:#"Helvetica" size:13];
self.excuse_auteur.textColor = [UIColor darkGrayColor];
self.excuse_auteur.textAlignment = NSTextAlignmentLeft;
self.excuse_auteur.frame = CGRectMake(margin, margin, viewBounds.size.width-dateWidth-(margin*2), 20);
[self addSubview:self.excuse_auteur];
// setup excuse_texte
self.excuse_texte = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(dateFrame)+margin/2, viewBounds.size.width - (margin*3), 200)];
self.excuse_texte.lineBreakMode = NSLineBreakByWordWrapping;
self.excuse_texte.numberOfLines = 0;
self.excuse_texte.font = [UIFont fontWithName:#"Helvetica" size:17];
self.excuse_texte.autoresizingMask = UIViewAutoresizingNone;
[self addSubview:self.excuse_texte];
CGRect textFrame = self.excuse_texte.frame;
// setup up image
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"up-small"]];
self.img = imageView;
[self addSubview:self.img];
imageView.frame = CGRectMake(20, CGRectGetMaxY(textFrame)+margin/2, 20, 20);
// setup up
self.up = [[UILabel alloc] initWithFrame:CGRectMake(45, CGRectGetMaxY(textFrame)+margin/2+2, viewBounds.size.width - margin*2, 20)];
self.up.font = [UIFont fontWithName:#"Helvetica" size:11];
self.up.textColor = [UIColor darkGrayColor];
self.up.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.up];
}
return self;
}
My cellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BBExcuse *excuse = [self.list objectAtIndex:indexPath.row];
static NSString *cellIdentifier = #"Cell";
// Similar to UITableViewCell, but
BBTableViewCell *cell = (BBTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[BBTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.excuse_texte.text = excuse.excuse_texte;
// #TODO problem here ?
[cell.excuse_texte sizeToFit];
cell.excuse_auteur.text = excuse.excuse_auteur;
cell.excuse_date.text = excuse.excuse_date;
cell.up.text = [NSString stringWithFormat:#"%#", excuse.up];
cell.img.frame = CGRectMake(20, CGRectGetMaxY(cell.excuse_texte.frame)+20/2, 20, 20);
cell.up.frame = CGRectMake(45, CGRectGetMaxY(cell.excuse_texte.frame)+20/2+2, 20, 20);
// setup up
return cell;
}
Ok solved by removing sizeToFit and specify height and width in cellForRowAtIndexPath
cell.excuse_texte.text = excuse.excuse_texte;
NSString *str = excuse.excuse_texte;
UILabel *gettingSizeLabel = [[UILabel alloc] init];
gettingSizeLabel.font = [UIFont systemFontOfSize:17];
gettingSizeLabel.text = str;
gettingSizeLabel.numberOfLines = 0;
gettingSizeLabel.lineBreakMode = NSLineBreakByWordWrapping;
CGSize maximumLabelSize = CGSizeMake(260.0f, 9999.0f);
CGSize theSize = [gettingSizeLabel sizeThatFits:maximumLabelSize];
// on resize sans sizetofit
cell.excuse_texte.frame = CGRectMake(cell.excuse_texte.frame.origin.x, cell.excuse_texte.frame.origin.y, cell.excuse_texte.frame.size.width, theSize.height);

Slow loading tableview on iPhone with reusable cells

I load the data from Parse.com backend, they send me a solutions for use the reusable cells but now I still have troubles with the loading speed, this is the coding I have in my tableview and I have a Subclass for making up my cells (ExploreStreamCustomCell.m)
- (ExploreStreamCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *CellIdentifier = #"ExploreStreamCustomCell";
ExploreStreamCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ExploreStreamCustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
// Configure the cell
cell.listItemTitle.text = [object objectForKey:#"text"];
cell.checkinsLabel.text = [NSString stringWithFormat:#"%#", [object objectForKey:#"checkins"]];
cell.descriptionLabel.text = [object objectForKey:#"description"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
PFFile *listThumbnail = [object objectForKey:#"header"];
cell.listViewImage.image = [UIImage imageNamed:#"loading_image_stream.png"]; // placeholder image
cell.listViewImage.file = listThumbnail;
[cell.listViewImage loadInBackground:NULL];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForNextPageAtIndexPath:indexPath];
cell.textLabel.font = [cell.textLabel.font fontWithSize:kPAWWallPostTableViewFontSize];
return cell;
}
If I have all the content of the //configure cell in the cell == nil the it's fast but it show up 3 of the 9 unique datarows and repeat those 3 unique content cell 3 times?
Edit extra code within ExploreStreamCustomCell.m
#import "ExploreStreamCustomCell.h"
#implementation ExploreStreamCustomCell
#synthesize listViewImage,
iconLocation,
iconPeople,
iconCheckins,
listItemTitle,
locationLabel,
peopleLabel,
checkinsLabel,
descriptionLabel,
listItemView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
//Initialization code
listItemView = [[UIView alloc] init];
listViewImage = [[PFImageView alloc] init];
iconLocation = [[UIImageView alloc] init];
iconPeople = [[UIImageView alloc] init];
iconCheckins = [[UIImageView alloc] init];
listItemTitle = [[UILabel alloc] init];
locationLabel = [[UILabel alloc] init];
peopleLabel = [[UILabel alloc] init];
checkinsLabel = [[UILabel alloc] init];
descriptionLabel = [[UILabel alloc] init];
listViewImage.image = [UIImage imageNamed:#"nachtwacht_list_formaat.png"];
iconLocation.image = [UIImage imageNamed:#"icon_magenta_location.png"];
iconPeople.image = [UIImage imageNamed:#"icon_magenta_people.png"];
iconCheckins.image = [UIImage imageNamed:#"icon_magenta_checkins.png"];
listItemTitle.text = #"text";
locationLabel.text = #"0,7 km";
peopleLabel.text = #"34";
checkinsLabel.text = #"61";
descriptionLabel.text = #"Description text.";
[self.contentView addSubview:listItemView];
[self.contentView addSubview:listViewImage];
[self.contentView addSubview:iconLocation];
[self.contentView addSubview:iconPeople];
[self.contentView addSubview:iconCheckins];
[self.contentView addSubview:listItemTitle];
[self.contentView addSubview:locationLabel];
[self.contentView addSubview:peopleLabel];
[self.contentView addSubview:checkinsLabel];
[self.contentView addSubview:descriptionLabel];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+0 , 33, 280, 124);
listViewImage.frame = frame;
listViewImage.contentMode = UIViewContentModeScaleAspectFill;
listViewImage.layer.masksToBounds = YES;
//listViewImage.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+20 , 164, 12, 18);
iconLocation.frame = frame;
//iconLocation.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+102 , 164, 24, 18);
iconPeople.frame = frame;
//iconPeople.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+193 , 164, 20, 16);
iconCheckins.frame = frame;
//iconLocation.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+0 , 0, 280, 33);
listItemView.frame = frame;
listItemView.backgroundColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
frame= CGRectMake(boundsX+20 , 3, 240, 29);
listItemTitle.frame = frame;
//listItemTitle.textColor = [UIColor colorWithRed:250.0f/255.0f green:194.0f/255.0f blue:9.0f/255.0f alpha:0.8f];
listItemTitle.textAlignment = UITextAlignmentLeft;
listItemTitle.font = [UIFont boldSystemFontOfSize:15];
listItemTitle.textColor = [UIColor whiteColor];
listItemTitle.backgroundColor = [UIColor clearColor];
listItemTitle.lineBreakMode = UILineBreakModeTailTruncation;
//listItemTitle.backgroundColor = [UIColor orangeColor];
frame= CGRectMake(boundsX+40 , 164, 57, 21);
locationLabel.frame = frame;
locationLabel.textAlignment = UITextAlignmentLeft;
locationLabel.font = [UIFont boldSystemFontOfSize:12];
locationLabel.textColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
locationLabel.backgroundColor = [UIColor clearColor];
locationLabel.lineBreakMode = UILineBreakModeTailTruncation;
locationLabel.numberOfLines = 1;
//locationLabel.backgroundColor = [UIColor redColor];
frame= CGRectMake(boundsX+134 , 164, 57, 21);
peopleLabel.frame = frame;
peopleLabel.textAlignment = UITextAlignmentLeft;
peopleLabel.font = [UIFont boldSystemFontOfSize:12];
peopleLabel.textColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
peopleLabel.backgroundColor = [UIColor clearColor];
peopleLabel.lineBreakMode = UILineBreakModeTailTruncation;
peopleLabel.numberOfLines = 1;
frame= CGRectMake(boundsX+221 , 164, 51, 21);
checkinsLabel.frame = frame;
checkinsLabel.textAlignment = UITextAlignmentLeft;
checkinsLabel.font = [UIFont boldSystemFontOfSize:12];
checkinsLabel.textColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
checkinsLabel.backgroundColor = [UIColor clearColor];
checkinsLabel.lineBreakMode = UILineBreakModeTailTruncation;
checkinsLabel.numberOfLines = 1;
frame= CGRectMake(boundsX+0 , 189, 280, 55);
descriptionLabel.frame = frame;
descriptionLabel.textAlignment = UITextAlignmentLeft;
descriptionLabel.font = [UIFont systemFontOfSize:13];
descriptionLabel.backgroundColor = [UIColor clearColor];
descriptionLabel.lineBreakMode = UILineBreakModeTailTruncation;
descriptionLabel.numberOfLines = 3;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
/*
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
A great way to explore the inefficiencies of your code is to use Instruments' Time Profiler tool. The Time Profiler will let you see how much time is being spent on each task, line-by-line in your code.
I would recommend the following settings for profiling:
From Apple's Face Detection sample app:
You can then double click any line (higher percentages mean more time is being devoted to that method call) to see in the code how much time is spent in each place.
From here you can begin to figure out where you are being inefficient and see exactly what is taking up so much time. Good luck!

Resources