先上代码

UIButton *settingBtn = [Utils creatCustomButtonWithFrame:CGRectMake(, , , ) btnTitle:@"设置" btnFontSize: titleColor:[UIColor blackColor]];
[settingBtn addTarget:self action:@selector(clickTheSettingBtn) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithCustomView:settingBtn];
self.navigationItem.rightBarButtonItem = rightBar;

效果为

若想调节该按钮位置,设置

settingBtn.titleLabel.textAlignment = NSTextAlignmentRight;

这样是没效果的。应利用UIBarButtonSystemItemFixedSpace格式,rightbar设为数组,进行填充。

UIButton *settingBtn = [SHUtils creatCustomButtonWithFrame:CGRectMake(, , , ) btnTitle:@"设置" btnFontSize: titleColor:[UIColor blackColor]];
[settingBtn addTarget:self action:@selector(clickTheSettingBtn) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithCustomView:settingBtn];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -;
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,rightBar,nil];

效果为

修改navigationbar右侧按钮离屏幕边缘位置的更多相关文章

  1. iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button

    //两个按钮的父类view UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(, , , )]; //历史浏览按钮 ...

  2. iOS 自定义NavigationBar右侧按钮rightBarButtonItem

    自定义右侧的一个按钮 UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"主页" style: ...

  3. 在使用element-ui搭建的表格中,实现点击"定位"按钮后,屏幕滚动到对应行的位置

    背景: 一个后台管理系统,当管理员登录之后,会存在一个自己的id值, 在一个表格中,当点击"定位"按钮后,屏幕滚动到拥有管理员id的这一行,并且给设置一个高亮的背景 相关知识点: ...

  4. [iOS微博项目 - 1.5] - NavigationBar标题按钮

    A.NavigationBar标题按钮 1.需求 在“首页”的导航栏中部设置一个“首页”文字+箭头按钮 统一设置样式 根据实际文本长度调整宽度 消除系统自带的点击高亮效果 点击按钮,箭头上下颠倒 gi ...

  5. 点击提交按钮,屏幕会出现闪烁问题,element.style问题

    点击提交按钮,屏幕会出现闪烁问题 通过后台调试发现,在点击的按钮的时候会给body添加一个padding值,而且会出现怎么都修改不了的问题,会发现里面会有 element.style的值,这其实是一种 ...

  6. Swift实现封装PopMenu菜单,可在屏幕任意位置弹出

    效果图: 说明: 代码现已支持 Swift3 语法 使用介绍: 1.初始化位置 //frame 为整个popview相对整个屏幕的位置 箭头距离右边位置,默认15 //popMenu = SwiftP ...

  7. IOS 修改UIAlertController的按钮标题的字体颜色,字号,内容

    IOS 修改UIAlertController的按钮标题的字体颜色,字号,内容 UIAlertController *alertVC = [UIAlertController alertControl ...

  8. WPF 获得鼠标相对于屏幕的位置,相对于控件的位置

    相对于屏幕的位置 第一步: /// <summary>    /// 用于获得鼠标相对于屏幕的位置    /// </summary>    public class Win3 ...

  9. iOS七大手势之(平移、捏合、轻扫、屏幕边缘轻扫)手势识别器方法

    使用手势很简单,分为两步: 创建手势实例.当创建手势时,指定一个回调方法,当手势开始,改变.或结束时,回调方法被调用. 添加到需要识别的View中.每个手势只对应一个View,当屏幕触摸在View的边 ...

随机推荐

  1. js监听rem实现响应式

    原文链接:http://caibaojian.com/web-app-rem.html (function (doc, win) { var docEl = doc.documentElement, ...

  2. knockout 学习实例3 html

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. Func<T>与Action<T>委托泛型介绍

    .Net 3.5之后,微软推出了Func<T>与Action<T>泛型委托.进一步简化了委托的定义. Action<T>委托主要的表现形式如下: public de ...

  4. CSS 派生选择器

    派生选择器 通过依据元素在其位置的上下文关系来定义样式,你可以使标记更加简洁. 在 CSS1 中,通过这种方式来应用规则的选择器被称为上下文选择器 (contextual selectors),这是由 ...

  5. Delphi 2010错误 "displayNotification: 内存不够"

    打开 Delphi 2010 的时候, 它报一个错误 "displayNotification: 内存不够",从而无法使用 Delphi , 解决办法 摘自http://www.cnblogs.com ...

  6. android学习笔记53——自动朗读TTS

    自动朗读TTS android提供了自动朗读功能--其指的是支持可以对指定文本内容进行朗读,从而发出声音: 同时android的自动朗读支持还允许把文本对应的音频录制成音频文件,方便后续播放. 这种自 ...

  7. [zz] Pixar’s OpenSubdiv V2: A detailed look

    http://www.fxguide.com/featured/pixars-opensubdiv-v2-a-detailed-look/ Pixar’s OpenSubdiv V2: A detai ...

  8. ADF_Desktop Integration系列2_ADF桌面集成入门之开发简单ADF Desktop Excel

    2013-05-01 Created By BaoXinjian

  9. mysql日志详细解析

    MySQL日志: 主要包含:错误日志.查询日志.慢查询日志.事务日志.二进制日志: 日志是mysql数据库的重要组成部分.日志文件中记录着mysql数据库运行期间发生的变化:也就是说用来记录mysql ...

  10. Codeforces Round #229 (Div. 2) D

    D. Inna and Sweet Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...