ios uitableview和navigationbar的常用設置詳解
tableview:
1.tableview常用基本設置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
// 清除父類uiedgeinsets self.tableview.contentinset = uiedgeinsetsmake(0, 0, 0,0); //禁止滾動 self.tableview.scrollenabled = no; // tableview頭部視圖設置 self.tableview.tableheaderview =一個uiview; //tableview尾部視圖設置,這樣用一個不占空間的uiview初始化可以清除尾部多余空格 self.tableview.tablefooterview = [[uiview alloc]initwithframe:cgrectzero]; //表格背景色 self.tableview.backgroundcolor = [uicolorgraycolor]; //取消垂直滾動條 self.tableview.showsverticalscrollindicator=no; //設置表格背景圖片 uiview *bgview= [[uiview alloc]initwithframe:cgrectmake(0,20,slapplicationw,slapplicationh)]; uiimageview *bgimageview= [[uiimageview alloc]initwithframe:cgrectmake(0,0,slapplicationw,slapplicationh)]; [bgimageview setimage:[uiimageimagenamed:@ "tree" ]]; [bgview addsubview:bgimageview]; self.tableview.backgroundview= bgview; |
2.cell常用基本設置
1
2
3
4
5
6
|
//表格附件樣式,指示箭頭 cell.accessorytype=uitableviewcellaccessorydisclosureindicator; //禁止點擊變色 cell.selectionstyle=uitableviewcellselectionstylenone; |
3.cell分割線左側空白清除
1
2
3
4
|
//分割線清偏移 if ([cell respondstoselector:@selector(setseparatorinset:)]) { [cellsetseparatorinset:uiedgeinsetszero]; } |
1
2
3
4
5
|
//分割線清邊界(沒啥變化) if ([cell respondstoselector:@selector(setlayoutmargins:)]) { [cellsetlayoutmargins:uiedgeinsetszero]; } <br> |
1
2
3
4
5
|
//清除父邊界 if ([cell respondstoselector:@selector(setpreservessuperviewlayoutmargins:)]){ [cellsetpreservessuperviewlayoutmargins:no]; } |
navigationbar導航欄:
1.常用基本設置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
self.title =@ "標題" ; // 導航欄顏色 self.navigationbar.bartintcolor=[uicolor graycolor]; // 導航欄文字顏色 self.navigationbar.tintcolor=[uicolor whitecolor]; // 導航欄標題顏色 nsmutabledictionary*textattrs= [nsmutabledictionary dictionary]; textattrs[nsforegroundcolorattributename] =[uicolor whitecolor]; self.navigationbarsettitletextattributes:textattrs]; //導航欄按鈕1 uibarbuttonitem*button1= [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemaddtarget:selfaction:@selector(function1)]; //導航欄按鈕2 uibarbuttonitem*button2= [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemsearchtarget:selfaction:@selector(function2)]; //將按鈕添加到導航欄右側(可以添加多個) self.navigationitem.rightbarbuttonitems=@[button1, button2]; |
2.系統自帶按鈕
枚舉定義及樣式解釋如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
typedef ns_enum(nsinteger, uibarbuttonsystemitem) { uibarbuttonsystemitemdone, //done英文字符 uibarbuttonsystemitemcancel, //cancel uibarbuttonsystemitemedit, //edit uibarbuttonsystemitemsave, //save uibarbuttonsystemitemadd, //圖標1(加號圖標?) uibarbuttonsystemitemflexiblespace, //?空白 uibarbuttonsystemitemfixedspace, //?空白 uibarbuttonsystemitemcompose, //圖標2(寫字板上一支筆寫字的圖標) uibarbuttonsystemitemreply, //圖標3 uibarbuttonsystemitemaction, //圖標4 uibarbuttonsystemitemorganize, //圖標5 uibarbuttonsystemitembookmarks, //<span style="font-family: menlo;">圖標6</span> uibarbuttonsystemitemsearch, //<span style="font-family: menlo;">圖標7</span> uibarbuttonsystemitemrefresh, //<span style="font-family: menlo;">圖標8</span> uibarbuttonsystemitemstop, //圖標9 uibarbuttonsystemitemcamera, //圖標10 uibarbuttonsystemitemtrash, //圖標11 uibarbuttonsystemitemplay, //圖標12 uibarbuttonsystemitempause, //圖標13 uibarbuttonsystemitemrewind, //圖標14 uibarbuttonsystemitemfastforward, //圖標15 uibarbuttonsystemitemundo ns_enum_available_ios(3_0), //redo uibarbuttonsystemitemredo ns_enum_available_ios(3_0), //undo uibarbuttonsystemitempagecurl ns_enum_available_ios(4_0), //?空白 }; |
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!