I am learning iOS
for the first time while building an app. In one of the requirements, the UITableViewCell
needs to look like
(PS: This is just a design, no code was written for this)
However, when I design my UITableViewCell
, it looks like
and the code to generate this looks like
- (void)setTransactionCell:(TransactionCell *)transactionCell transactionModel:(TransactionModel *)transactionModel {
transactionCell.dateOfMonth.image = [self getDayImage:[UIImage imageNamed:@"1"]];
transactionCell.dayOfWeek.image = [self getDayImage:[UIImage imageNamed:@"Sun"]];
transactionCell.name.text = transactionModel.name;
transactionCell.name.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
transactionCell.amount.text = transactionModel.amount;
transactionCell.amount.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
transactionCell.categoryImage.image = [self getCategoryImage:[UIImage imageNamed:transactionModel.category]];
transactionCell.imageView.contentMode = UIViewContentModeCenter;
}
- (UIImage *)getDayImage: (UIImage *) image {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(30, 30), NO, 0);
[image drawInRect:CGRectMake(0, 0, 15, 15)];
UIImage *im2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return im2;
}
- (UIImage *)getCategoryImage:(UIImage *)image {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(40, 40), NO, 0);
[image drawInRect:CGRectMake(0, 0, 36, 36)];
UIImage *im2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return im2;
}
and finally when I run the application, I see
I am fairly new and not sure what is going wrong. I desperately tried dragging labels and images to every possible combination but nothing worked. I am missing something really basic, can you one please guide what is wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…