zoukankan      html  css  js  c++  java
  • IOS7 自定义UIBarButtonItem 的一些问题

    ios 下自定义导航栏的BarButtonItem 会产生一些偏移问题,

    解决方案: 通过新建一个系统的带固定距离的Item来调节你的Item

    #define   IOS7_NAVI_SPACE   -10
    }
        [self.navigationItem setLeftBarButtonItems:[self getBackBarButtonitem]];
    }
    
    //返回按钮
    -(NSArray *)getBackBarButtonitem{
        //自定义button
        UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 55, 35)];
        //设置背景图片
        [button setBackgroundImage:[UIImage imageNamed:@"nav_left_btn_unselected.png"] forState:UIControlStateNormal];
        //设置文字
        [button setTitle:@"返回" forState:UIControlStateNormal];
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        //设置文字颜色
        [button setTintColor:[UIColor whiteColor]];
        //为TouchUpInside添加行为
        [button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
        //初始化一个BarbuttonItem
        UIBarButtonItem *Item=[[UIBarButtonItem alloc] initWithCustomView:button];
        
        //在初始化一个系统的带有固定距离的占位的BarButtonItem 占位用
        UIBarButtonItem *fixedSpace=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
        fixedSpace.width=IOS7_NAVI_SPACE;//设置宽度
    // 把带固定距离的Item放在前面,调整距离     return [[NSArray alloc] initWithObjects:fixedSpace,Item, nil]; }
  • 相关阅读:
    面试题15:链表中倒数第K个结点
    面试题31:连续子数组的最大和
    数据库索引实例
    面试题27:二叉搜索树与双向链表
    面试题28:字符串的排列
    java比较器Comparable接口和Comaprator接口
    面向对象知识汇总
    虚函数与纯虚函数
    Linux IO实时监控iostat命令详解
    hive GroupBy操作(翻译自Hive wiki)
  • 原文地址:https://www.cnblogs.com/niit-soft-518/p/4029923.html
Copyright © 2011-2022 走看看