網上下載了一個ios做瀑布流圖片展示源碼,之前借助做web的經驗,我已為ios類似於css style中有個float:left的效果,然后形成瀑布流效果,或者像用html中做個表格分成一行幾列,然后在里面填充內容。
剛下載瀑布流demo大致意路是這樣:
1. 總先做成幾列是事先要清楚,有多少條記錄,這個可以從json或者xml中讀取后知道(json或xml最好將圖片的高度和寬度也顯示出來,便於后面用到)。
2. 假設要做成3列,就用三個uitableview,寬度平均,高度動態,頁面高度取uitableview中最高的。
3. 三個uitableview初始化的時候用到tag(我越來越覺得tag在ios中的用處很大,就像js中讀取html控件中的id一樣),然后showsVerticalScrollIndicator和scrollEnabled設為no,separatorStyle設為UITableViewCellSeparatorStyleNone,添加到UIview中
4.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 當行記錄數/列; }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ int arrIndex= 當前indexPath.row * 列(3)+當前indexPath.column;| return [[XML/JSON objectAtIndex:arrIndex] objectForKey:@"高度"]; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //從數據源中得到當前數組對應的數據,然后再用uitableviewcell填充 }
感謝源碼作者下載地址:http://code4app.com/codesample/4fdfecd96803fa117f000000