【发布时间】:2014-09-10 20:43:04
【问题描述】:
我在构建应用程序时第一次学习iOS。在其中一项要求中,UITableViewCell 需要看起来像
(PS:这只是一个设计,没有为此编写代码)
但是,当我设计我的 UITableViewCell 时,它看起来像
生成它的代码如下所示
- (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;
}
最后,当我运行应用程序时,我看到了
我还很新,不知道出了什么问题。我拼命尝试将标签和图像拖到每个可能的组合中,但没有任何效果。我错过了一些非常基本的东西,请您指导一下出了什么问题?
【问题讨论】:
标签: ios objective-c uitableview