zoukankan      html  css  js  c++  java
  • 导航栏右侧添加按钮 (标题+图片)

    1 ,按钮上面添加标题和图片

    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];

        addButton.frame = CGRectMake(10, 0, 80, 40);

        [addButton setImage:[UIImage imageNamed:@"btn_sx"] forState:UIControlStateNormal];

        [addButton setImageEdgeInsets:UIEdgeInsetsMake(5, 55, 5, 5)];

        [addButton setTitle:@"查询" forState:UIControlStateNormal];

        [addButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -60, 0, 0)];

        [addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

        addButton.titleLabel.font = [UIFont systemFontOfSize:15];

        [addButton addTarget:self action:@selector(searchPeople) forControlEvents:UIControlEventTouchUpInside];

        addButton.backgroundColor = [UIColor clearColor];

        testView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 80.0, 44.0)];

        [testView addSubview: addButton];

        testView.hidden = YES;

        searchItem = [[UIBarButtonItem alloc] initWithCustomView:testView];

        self.navigationItem.rightBarButtonItem = searchItem;

    2.只添加图片或者标题

    UIBarButtonItem *searchItem  = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"cs_search"] style:UIBarButtonItemStylePlain target:self action:@selector(searchPeople)];

    UIBarButtonItem *searchItem = [[UIBarButtonItem alloc]initWithTitle:@"查询" style:UIBarButtonItemStylePlain target:self action:@selector(searchPeople)];

  • 相关阅读:
    《ACM国际大学生程序设计竞赛题解I》——6.8
    数据结构篇
    从SG函数浅谈解决博弈问题的通法
    动态规划的泛式解题思路
    bzoj1057: [ZJOI2007]棋盘制作
    bzoj3884: 上帝与集合的正确用法
    bzoj1564: [NOI2009]二叉查找树
    bzoj4347: [POI2016]Nim z utrudnieniem
    bzoj1131: [POI2008]Sta
    bzoj1566: [NOI2009]管道取珠
  • 原文地址:https://www.cnblogs.com/Lovexiaohuzi/p/6688184.html
Copyright © 2011-2022 走看看