cell圓角效果的繪製

2021-07-12 06:36:14 字數 2099 閱讀 8241

圓角的cell,之前ios 6的時候是這種的(擬物),ios 7 (扁平化)之後就進行了修改!

主要的實現在tableview的**方法中 - (void)tableview:willdisplaycell: forrowatindexpath: ,繪製table view cell 的背景view。

下面的**,你可以直接拷貝到控制器中演示效果,如果要整合到你自己的**中,你需要把 - (void)tableview:willdisplaycell: forrowatindexpath: 這個方法中的東西拷貝過去,還要修改table view 的樣式是分組和分割線為 none,這些在 - viewdidload中你也可以找到。

//  圓角cell

#import "viewcontroller.h"

@inte***ce

viewcontroller ()

@property (strong, nonatomic)nsarray *datasource;

@end

@implementation

viewcontroller

//懶載入--資料來源

- (nsarray *)datasource

return _datasource;

}- (void)viewdidload

#pragma mark- uitableviewdelegate or datasource

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview

//單元格的個數

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section

//cell建立

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

cell.textlabel

.text = self

.datasource[indexpath.section][indexpath.row];

cell.imageview

.image = [uiimage imagenamed:@"icon"];

return cell;

}#pragma mark- cell 將要顯示的時候呼叫這個方法,就在這個方法內進行圓角繪製

/**本質:就是修改cell的背景view,這個view的layer層自己分局cell的型別(頂,底和中間)來繪製*/

- (void)tableview:(uitableview *)tableview willdisplaycell:(uitableviewcell *)cell forrowatindexpath:(nsindexpath *)indexpath

else

if (indexpath.row == 0)

else

if (indexpath.row == [tableview numberofrowsinsection:indexpath.section]-1)

else

layer.path = pathref;

cfrelease(pathref);

layer.fillcolor = [uicolor whitecolor].cgcolor; //cell的填充顏色

layer.strokecolor = [uicolor lightgraycolor].cgcolor; //cell 的邊框顏色

if (addline == yes)

uiview *bgview = [[uiview alloc] initwithframe:bounds];

[bgview.layer insertsublayer:layer atindex:0];

bgview.backgroundcolor = uicolor

.clearcolor;

cell.backgroundview = bgview;

}}@end

效果圖:

圓角視窗繪製

對於form,當borderstyle none時,繪製圓角,需要使用graphicspath的addarc方法。程式如下 從控制項左邊起點畫可以出席那邊框,但是當從控制項右邊框使用 理論值畫時,右邊框不會出現邊框,不清楚是為什麼,我只好把橫座標左移1畫素,即 rect.height iradius...

textview圓角效果

在開發android應用的時候,經常出現矩形textview 很不美觀,想把它變成圓角,怎麼辦呢,請看下面 首先在drawable檔案下建乙個corner view.xml檔案 如下 solid為填充顏色,如果不寫,將是預設的黑色,我這裡設定成白色 然後把你的textview例項物件呼叫 msign...

android 圓角效果

最近做乙個效果,要乙個上邊兩個角為圓角,下面兩個角為直角的四邊形白色背景 如下圖 這裡用到了shape屬性中的corners 屬性,api原文中是這樣 單一設定android radius integer 時,表示四個角都為integer畫素的圓角 這裡我開始的時候這樣設定了四個屬性 結果發現四個角...