想像Pinterest一样制作详细视图

时间:2014-05-26 00:08:37

标签: ios objective-c tableview pinterest

我整个周末一直在使用xcode中的观点,但仍然无法按照我的意愿获得它。我想做像Pinterest这样的详细视图(参见下面的链接),但无法找到如何做到这一点,它是一个包含自定义单元格,集合视图或其他内容的桌面视图。哪种方式是最简单的方法建立吗?如果有人为我提供了一些好的投入,那将是非常感激的..

即将到来的一周!

Pinterest DeatilView

编辑:这就是我现在所得到的......但感觉应该有更简单的方法......

#import "ViewController.h"

enum TableSectionSelected
{
kUIMainContentSection = 0,
kUISecondSection,
kUIActivateSection
};

@interface ViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];


self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
self.imageView.image = [UIImage imageNamed:@"fotolia_54424692.jpg"];
}

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
    case 0:
        return 2;
        break;
    default:
        return 1;
        break;
   }
 }

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath     *)indexPath
{
NSIndexPath *firstCell = [NSIndexPath indexPathForRow:0 inSection:0];

if ([firstCell isEqual:indexPath]) {
    return 500;
 }

 return 44;
 }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath    *)indexPath
 { 
 static NSString *CellIdentifier = @"Cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier            forIndexPath:indexPath];

//    cell.textLabel.text = [NSString stringWithFormat:@"%@", indexPath];

if (indexPath.section == 0 && indexPath.row == 0) {

}


switch (indexPath.section) {
    case kUIMainContentSection:
        if (indexPath.row == 0) {
            [cell.contentView addSubview:self.imageView];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 320, 260,   30)];
            titleLabel.text = @"Orange Juice";
            [cell.contentView addSubview:titleLabel];
            UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 370, 260, 44)];
            detailLabel.numberOfLines = 0;
            detailLabel.text = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium   adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolo";
            [detailLabel sizeToFit];
            [cell.contentView addSubview:detailLabel];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

        } else if (indexPath.row == 1) {
            cell.textLabel.text = @"Hitta Hit";
            cell.imageView.image = [UIImage imageNamed:@"fotolia_54424692.jpg"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle = UITableViewCellSelectionStyleDefault;

        }
        break;
    case kUISecondSection:
        cell.textLabel.text = @"Joe & The Juice";
        cell.imageView.image = [UIImage imageNamed:@"fotolia_54424692.jpg"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;


        break;
    case kUIActivateSection:
        cell.textLabel.text = @"Activate";
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.imageView.image = nil;
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
        break;
    default:
        break;
}

cell.layer.cornerRadius = 3.0;
cell.layer.borderColor = [UIColor colorWithHue:0.0 saturation:0.0 brightness:0.0 alpha:0.1].CGColor;
cell.layer.borderWidth = 0.5;



return cell;
 }

 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section == kUISecondSection) {
    return @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu,   sed do eiusmod tempor incididunt ut labore et dolo";
} else {
    return @"";
}
}

@end

1 个答案:

答案 0 :(得分:1)

他们正在使用UICollectionViews和新的过渡API。

这是一篇实际的博客文章,他们会在一些高级别的布局中浏览:
https://medium.com/@Pinterest_Engineering/behind-the-pins-building-pinterest-3-0-for-ios-100f57f6940

这是一个用于重建主要布局的UICollectionView布局:
https://github.com/chiahsien/CHTCollectionViewWaterfallLayout