我在構建應用程序時第一次學習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