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), //?空白 }; |
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!