2014-09-24 117 views
1

我見過很多關於如何將漸變效果應用於TableView的單元格的教程,但我想要實現的是讓用戶選擇基本顏色,然後在所有單元格中創建漸變效果的表格。與此相似:iOS TableView漸變效果

http://realmacsoftware.com/clear/

如果任何人有關於如何實現這一目標的任何想法,這將是偉大的!

回答

4

你只需要計算cellForRowAtIndexPath中的每種顏色:並將其設置在那裏。

一些假代碼我鞭打給你一個想法。

- (UIColor *)colorForRow:(NSInteger)row withTotalRows:(NSInteger)totalRows { 
// code to calculate the colors, you can use total rows to insure the end color. 
// You will want to calculate the percentage of each color for your gradient. 

    return color; 
} 

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Get your cell first 

    NSInteger totalRows = [self numberOfRowsInSection:indexPath.section]; 
    cell.contentView.backgroundColor = [self colorForRow:indexPath.row withTotalRows:totalRows]; 

} 
+0

謝謝你,會放棄它! – user3744562 2014-09-24 18:00:32