IOS UITableView和NavigationBar的常用设置详解

所属分类: 软件编程 / IOS 阅读数: 870
收藏 0 赞 0 分享

IOS UITableView和NavigationBar的常用设置详解

TableView:

1.tableview常用基本设置

// 清除父类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常用基本设置

//表格附件样式,指示箭头 
  
  cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; 
//禁止点击变色 
  
  cell.selectionStyle=UITableViewCellSelectionStyleNone; 

3.cell分割线左侧空白清除     

//分割线清偏移 
  if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { 
    [cellsetSeparatorInset:UIEdgeInsetsZero]; 
  } 
//分割线清边界(没啥变化) 
  if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { 
    [cellsetLayoutMargins:UIEdgeInsetsZero]; 
  } 

//清除父边界 
  if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){ 
    [cellsetPreservesSuperviewLayoutMargins:NO]; 
  
  } 

NavigationBar导航栏:

1.常用基本设置

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.系统自带按钮

枚举定义及样式解释如下:

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),  //?空白 
}; 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多精彩内容其他人还在看

iOS开发笔记--详解UILabel的相关属性设置

这篇文章主要介绍了iOS开发笔记--详解UILabel的相关属性设置,对初学者具有一定的参考价值,有需要的可以了解一下。
收藏 0 赞 0 分享

iOS中获取系统相册中的图片实例

这篇文章主要介绍了iOS中获取系统相册中的图片实例,具有一定的参考价值没有需要的朋友可以了解一下。
收藏 0 赞 0 分享

iOS 检测网络状态的两种方法

一般有Reachability和AFNetworking监测两种方式,都是第三方的框架,下文逐一详细给大家讲解,感兴趣的朋友一起看看吧
收藏 0 赞 0 分享

IOS 性能优化中离屏渲染

本文主要介绍了IOS 性能优化中离屏渲染的资料,提供了几种方法讲解了优化,有需要的小伙伴可以参考下
收藏 0 赞 0 分享

iOS获取当前设备型号等信息(全)包含iPhone7和iPhone7P

这篇文章主要介绍了iOS获取当前设备型号设备信息的总结包含iPhone7和iPhone7P,包括ios7之前之后的获取方式,本文接的非常详细,具有参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

iOS实现爆炸的粒子效果示例代码

之前在网上看到了一个Android实现的爆炸效果,感觉非常不错,所以自己尝试用iOS来实现下效果,现在将实现的过程、原理以及遇到的问题分享给大家,有需要的朋友们可以参考借鉴,下面来一起看看吧。
收藏 0 赞 0 分享

iOS毕业设计之天气预报App

这篇文章主要为大家详细介绍了iOS毕业设计之天气预报App,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

iOS轻点、触摸和手势代码开发

这篇文章主要为大家详细介绍了iOS轻点、触摸和手势代码开发,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

iOS 实现多代理的方法及实例代码

这篇文章主要介绍了iOS 实现多代理的方法及实例代码的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

iOS文字渐变色效果的实现方法

在大家日常开发iOS的过程中,可能会遇到要实现文字渐变色的效果,这篇文章文章通过示例代码和详细的步骤介绍了如何利用iOS实现文字渐变色的效果,实现后的很不错,感兴趣的朋友们下面来一起看看吧。
收藏 0 赞 0 分享
查看更多