自己定义导航栏:

//  CustomNaviBarView.h

#import <UIKit/UIKit.h>

@interface CustomNaviBarView : UIView
{
@private
/**
* 左側button
*/
UIButton* _leftButton;
/**
* 右側button
*/
UIButton* _rightButton;
/**
* 中部标签
*/
UILabel* _navTitle;
} @property(nonatomic,strong)UIButton* leftButton;
@property(nonatomic,strong)UIButton* rightButton;
@property(nonatomic,strong)UILabel* navTitle; /**
* 返回一个自己定义导航条
*
* @param controller 控制器对象
* @param leftTitle 导航左側文本,默认:@"取消"
* @param rightTitle 导航右側文本
* @param centerTitle 导航中部文本
*
* @return 导航条对象
*/
- (CustomNaviBarView*)initCustomNaviBarViewOnController:(UIViewController*)controller leftTitle:(NSString*)leftTitle rightTitle:(NSString*)rightTitle centerTitle:(NSString*)centerTitle; @end
//  CustomNaviBarView.m

#import "CustomNaviBarView.h"
#import "Constant.h" @implementation CustomNaviBarView @synthesize leftButton = _leftButton;
@synthesize rightButton = _rightButton;
@synthesize navTitle = _navTitle; - (CustomNaviBarView*)initCustomNaviBarViewOnController:(UIViewController*)controller leftTitle:(NSString*)leftTitle rightTitle:(NSString*)rightTitle centerTitle:(NSString*)centerTitle
{
//1.创建导航栏视图
self = [super initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, 65)];
if (self != nil)//当导航视图没有载入成功的时候推出该方法
{
//1.为导航视图设置背景
self.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:248 / 255.0 blue:248 / 255.0 alpha:1];
[[controller navigationController] setNavigationBarHidden:YES animated:YES]; //2.导航面板左边的取消按钮
_leftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
if (_leftButton != nil)
{
_leftButton.frame = CGRectMake(15, 20, 65, 44);
if (leftTitle != nil) {
[_leftButton setTitle:leftTitle forState: UIControlStateNormal];
}else
{
[_leftButton setTitle:POST_CANCEL_BUTTON forState: UIControlStateNormal];
}
[_leftButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];
_leftButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
_leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//[leftButton addTarget:self action:@selector(cancelButtonEventTouchUpInside)forControlEvents :UIControlEventTouchUpInside];
[self addSubview:_leftButton];
}
//3.导航面板右边的公布按钮
_rightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
if (_rightButton != nil)
{
[_rightButton setFrame:CGRectMake(WIDTH_SCREEN - 80, 20, 65, 44)];
if (_rightButton != nil) {
[_rightButton setTitle:rightTitle forState: UIControlStateNormal];
}else
{
//[rightButton setTitle:POST_CANCEL_BUTTON forState: UIControlStateNormal];
}
[_rightButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];
_rightButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
_rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
//[rightButton addTarget:self action:@selector(postButtonEventTouchUpInside)forControlEvents :UIControlEventTouchUpInside];
[self addSubview:_rightButton];
} //4.导航面板中部文字
_navTitle = [[UILabel alloc] initWithFrame:CGRectMake(80, 20, WIDTH_SCREEN - 80 - 80, 44)];
if (_navTitle != nil)
{
[_navTitle setTextColor:[UIColor blackColor]];
if (centerTitle != nil)
{
_navTitle.text = centerTitle;
}else
{
//navTitle.text = @"";
}
[_navTitle setTextAlignment:NSTextAlignmentCenter];
_navTitle.font = [UIFont systemFontOfSize:18.0];
[self addSubview:_navTitle];
} //5.在导航视图底加入切割线
UIView *navDividingLine = [[UIView alloc] init];
if (navDividingLine != nil)
{
navDividingLine.frame = CGRectMake(0, 20 + 44, WIDTH_SCREEN, 1);
navDividingLine.backgroundColor = [UIColor colorWithRed:221 / 255.0 green:221 / 255.0 blue:221 / 255.0 alpha:1];
[self addSubview:navDividingLine];
} //6.往view添加导航栏
//[controller.view addSubview:navView];
}
return self;
} @end

怎样使用:

    //1.创建导航
CustomNaviBarView* customNaviBarView = [[CustomNaviBarView alloc] initCustomNaviBarViewOnController:self leftTitle: nil rightTitle:NEWADDRESS_ADD_TITLE centerTitle:NEWADDRESS_NAVIGATION_TITLE];
if (customNaviBarView != nil)
{
[customNaviBarView.leftButton addTarget:self action:@selector(cancelButtonEventTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
[customNaviBarView.rightButton addTarget:self action:@selector(addButtonEventTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customNaviBarView];
}

自己定义切割线:

#import <UIKit/UIKit.h>

@interface CustomDividingLine : UIView

/**
* 创建一条切割线
*
* @param frame 位置及大小
* @param color 背景色,假设为空默认:#f2f2f2
*
* @return 新创建的切割线
*/
- (CustomDividingLine*)initDividingLineWithFrame:(CGRect)frame color:(UIColor*)color; @end
#import "CustomDividingLine.h"

@implementation CustomDividingLine

/**
* 创建一条切割线
*
* @param frame 位置及大小
* @param color 背景色
*
* @return 新创建的切割线
*/
- (CustomDividingLine*)initDividingLineWithFrame:(CGRect)frame color:(UIColor*)color
{
//3.2.1切割线
self = [super init];
if (self != nil)
{
self.frame = frame;
if (color != nil)
{
self.backgroundColor = color;
}
else
{
self.backgroundColor = [[UIColor alloc] initWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
}
}
return self;
} @end

怎样使用:

    //3.切割线
CustomDividingLine* customDividingLine = [[CustomDividingLine alloc]initDividingLineWithFrame:CGRectMake(0, 65 + 100, WIDTH_SCREEN, 1) color:nil];
if (customDividingLine != nil)
{
[self.view addSubview:customDividingLine];
}

ios 自己定义导航栏和切割线的更多相关文章

  1. iOS系统中导航栏的转场解决方案与最佳实践

    背景 目前,开源社区和业界内已经存在一些 iOS 导航栏转场的解决方案,但对于历史包袱沉重的美团 App 而言,这些解决方案并不完美.有的方案不能满足复杂的页面跳转场景,有的方案迁移成本较大,为此我们 ...

  2. 【转】iOS中设置导航栏标题的字体颜色和大小

    原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...

  3. iOS中设置导航栏标题的字体颜色和大小

    iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的 ...

  4. iOS学习——更改导航栏的返回按钮的标题与颜色

    转载自:修改navigationController返回按钮颜色和文字 今天在做项目时遇到这个问题,试了很多方法都失败了.最后终于找到正确的方案了,在这里分享给大家. 引言 在iOS开发过程中,Nav ...

  5. iOS:自定义导航栏,随着tableView滚动显示和隐藏

    自定义导航栏,随着tableView滚动显示和隐藏 一.介绍 自定义导航栏是APP中很常用的一个功能,通过自定义可以灵活的实现动画隐藏和显示效果.虽然处理系统的导航栏也可以实现,但是这个是有弊端的,因 ...

  6. 解决ios7.0 以后自己定义导航栏左边button靠右的问题

    1.自己定义button //左button UIButton *leftBtn = [[UIButton , , , )]; [leftBtn addTarget:self action:@sele ...

  7. iOS 动态修改导航栏颜色 UINavigationBar

    示例 所谓动态修改  意思是 在当前页面滚动的过程中 亦或 是在 触发返回事件\进入一个新的页面  导航栏的动态变化 由于系统级别的navBar 高度集成  很多自己想实现的功能 很不好弄 如果是通过 ...

  8. iOS 系统根据导航栏和状态栏自动修改布局

    问题 条件:1.有一个全屏大小的带导航的controller 2.隐藏导航栏,最顶上还会留出状态栏的位置,而不是全屏显示 解决方法 self.automaticallyAdjustsScrollVie ...

  9. iOS 滑动隐藏导航栏-三种方式

    /** 1隐藏导航栏-简单- */    self.navigationController.hidesBarsOnSwipe = YES; /** 2隐藏导航栏-不随tableView滑动消失效果 ...

随机推荐

  1. Android调试系列—使用android studio调试smali代码

    1.工具介绍 使用工具 android killer:用于反编译apk包,得到smali代码 android studio:调试smali代码工具,或者使用idea,android studio就是在 ...

  2. Layer中自定义属性的动画

    转载自:http://blog.jobbole.com/69211/ 默认情况下,CALayer 及其子类的绝大部分标准属性都可以执行动画,无论是添加一个 CAAnimation 到 Layer(显式 ...

  3. Winform改变Textbox边框颜色(转)

    namespace MyTextBoxOne { //使用时必须把文本框的BorderStyle为FixedSingle才能使用 //一些控件(如TextBox.Button等)是由系统进程绘制,重载 ...

  4. redis批量执行

    1.首先把redis命令放在txt文件中 eg: 文件名:  test.txt 内容如下: HMSET HM_001 name zhang01 age HMSET HM_002 name zhang0 ...

  5. VC获取当前程序运行路径

    /***************************************************/ /* 函数: 获取当前程序运行的路径 /* 返回: 当前程序运行路径 C:\AAA\BBB\ ...

  6. BZOJ4195 NOI2015 程序自动分析

    4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Description 在实现程序自动分析的过程中,常常需要判定一些约束条件 ...

  7. poj2378 树形DP

    C - 树形dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  8. QTableWidget简单操作

    使用Qt设计师工具,在窗体上添加Table Widget控件,这样就可以使用ui全局变量来调用该控件了. Table Widget控件的应用 (1)设置列数和行数 //设¦¨¨置?列¢D数ºy和¨ª行 ...

  9. Longest Palindromic Substring -LeetCode

    题目 Given a string s,find the longest palindromic substring in S.You may assume  that the maximum len ...

  10. Android开发笔记之: 数据存储方式详解

    无论是神马平台,神马开发环境,神马软件程序,数据都是核心.对于开发平台来讲,如果对数据的存储有良好的支持,那么对应用程序的开发将会有很大的促进作用.总体的来讲,数据存储方式有三种:一个是文件,一个是数 ...