自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS開發(fā) UItableView中的單元格背景漸變

移動開發(fā) iOS
漸變?nèi)绻帽尘皥D片,會讓你的app臃腫。給APP瘦身,我們可以使用代碼來解決漸變的問題。這篇文章是解決表格中的單元格的簡便問題,同時解決單元格外邊框問題。

iOS iPhone 開發(fā) UItableView中的單元格背景漸變

漸變?nèi)绻帽尘皥D片,會讓你的app臃腫。給APP瘦身,我們可以使用代碼來解決漸變的問題。這篇文章是解決表格中的單元格的簡便問題,同時解決單元格外邊框問題。

1:設(shè)置好開始顏色與結(jié)束顏色。推薦一個小工具,在chrome瀏覽器上安裝一個擴(kuò)展 chroma 這個東西能幫助你很好的選擇顏色。

下載地址:https://chrome.google.com/webstore/detail/chroma/gefgglgjdlddcpcapigheknbacbmmggp

[[75464]]

2:接下來就是代碼了 

創(chuàng)建一個 CellbackgroundVIew 

CellbackgroundVIew.h

  1. #import <UIKit/UIKit.h> 
  2.     @interface CellbackgroundVIew : UIView 
  3.     @end 

CellbackgroundVIew.m

  1. #import "CellbackgroundVIew.h" 
  2.     @implementation CellbackgroundVIew 
  3.     - (void)drawRect:(CGRect)rect 
  4.     { 
  5.         CGContextRef context = UIGraphicsGetCurrentContext(); 
  6.  
  7.         CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();    
  8.         // 創(chuàng)建起點(diǎn)顏色 白色 
  9.         CGColorRef beginColor = CGColorCreate(colorSpaceRef, (CGFloat[]){1.0f, 1.0f, 1.0f, 1.0f}); 
  10.         // 創(chuàng)建終點(diǎn)顏色 灰色 RGB(212,212,212) 這個色值我們可以從chroma擴(kuò)展插件中選擇 
  11.     <pre class="brush:cpp; toolbar: true; auto-links: false;">   //(CGFloat[]){0.83f, 0.83f, 0.83f, 1.0f} 0.83是 212/255的值</pre> 
  12.     CGColorRef endColor = CGColorCreate(colorSpaceRef, (CGFloat[]){0.83f, 0.83f, 0.83f, 1.0f}); 
  13.         CGRect paperRect = self.bounds; 
  14.         CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
  15.         CGFloat locations[] = {0.0,1.0}; 
  16.         NSArray *colors = [NSArray arrayWithObjects:(__bridge id)beginColor,(__bridge id)endColor, nil]; 
  17.         CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)CFBridgingRetain(colors), locations); 
  18.         CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); 
  19.         CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)); 
  20.         CGContextSaveGState(context); 
  21.         CGContextAddRect(context, rect); 
  22.         CGContextClip(context); 
  23.         CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0); 
  24.         CGContextRestoreGState(context); 
  25.         CGGradientRelease(gradient); 
  26.         CGColorSpaceRelease(colorSpace); 
  27.         //add line stroke 
  28.         CGRect strokeRect = CGRectInset(paperRect, 5.0, 5.0); 
  29.         CGColorRef lineColor = CGColorCreate(colorSpaceRef, (CGFloat[]){0.83f, 0.83f, 0.83f, 1.0f}); 
  30.         CGContextSetStrokeColorWithColor(context, lineColor); 
  31.         CGContextSetLineWidth(context, 1.0); 
  32.         CGContextStrokeRect(context, strokeRect); 
  33.     } 
  34.     @end 

在表格中我們的cell 可以設(shè)置backgroundview

  1. [cell setBackgroundView: [[CellbackgroundVIew alloc] init]]; 

 

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2010-08-11 16:41:30

Flex DataGr

2015-01-15 16:34:31

iOS源碼單元格

2009-08-07 17:54:41

C#單元格數(shù)據(jù)

2010-04-27 11:11:06

Oracle修改JTa

2011-07-07 16:38:21

iOS UITableVie

2021-08-13 11:10:32

OpenPyXLExcelPython

2023-06-07 10:41:43

2009-07-28 03:44:00

GridViewRow

2009-07-27 16:46:07

DetailsView

2021-09-09 08:58:32

Excel數(shù)據(jù)處理函數(shù)

2013-07-25 14:12:53

iOS開發(fā)學(xué)習(xí)UITableView

2011-08-15 13:44:07

iPhone開發(fā)UITableView

2013-06-20 11:21:58

iOS開發(fā)UITableView

2012-04-04 22:36:52

iOS5

2015-03-18 09:29:12

iOS開發(fā)爭議

2010-08-26 10:42:18

CSStr td

2021-11-15 07:45:06

CSS 技巧背景光動畫

2013-07-18 18:06:53

UITableview

2010-08-11 16:30:49

Flex DataGr

2011-06-15 10:49:26

Qt QTableItem
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號