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