我在构建应用程序时第一次学习iOS
。在要求之一,UITableViewCell
需要看起来像
(PS:这只是一个设计,没有代码为这个写的)iOS CustomTableViewCell:元素没有正确对齐
然而,当我设计我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;
}
最后当我运行应用程序,我看到
我是相当新的,不知道是怎么了。我拼命尝试拖拽标签和图像到每个可能的组合,但没有任何工作。我错过了一些非常基本的东西,你能指导一下什么是错的吗?
非常感谢吉姆,你的回答帮助我非常整齐地理解这一点,我甚至没有看到任何其他的自动布局,并能设计http://imgur.com/aJiPuTt。再次感谢 – daydreamer 2014-09-11 16:47:21