美文网首页
iOS如何修改UIBarButtonItem的间距

iOS如何修改UIBarButtonItem的间距

作者: RunningMan_Fly | 来源:发表于2016-04-21 18:26 被阅读1580次

    参考代码:主要设置创建一个UIBarButtonSystemItemFixedSpace样式的UIBarButtonItem,然后设置间距,代码如下:

    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    searchBtn.frame = CGRectMake(0,0,21, 21);

    //[searchBtn setTitle:@"搜索" forState:UIControlStateNormal];

    [searchBtn setBackgroundImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];

    [searchBtn setBackgroundImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateHighlighted];

    searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];

    [searchBtn addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:searchBtn];

    UIBarButtonItem *rightSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

    rightSpace.width = -7;

    self.navigationItem.rightBarButtonItems = @[rightSpace,rightItem];

    相关文章

      网友评论

          本文标题:iOS如何修改UIBarButtonItem的间距

          本文链接:https://www.haomeiwen.com/subject/cvitrttx.html