zoukankan      html  css  js  c++  java
  • 修改navigationbar右侧按钮离屏幕边缘位置

    先上代码

    UIButton *settingBtn = [Utils creatCustomButtonWithFrame:CGRectMake(0, 0, 60, 40) btnTitle:@"设置" btnFontSize:14 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(0, 0, 60, 40) btnTitle:@"设置" btnFontSize:14 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 = -20;
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,rightBar,nil];

    效果为

  • 相关阅读:
    HDU 5135(再思考)
    HDU 5105
    HDU 5135
    Codeforces 985E
    Codeforces 985D
    Codeforces 975D
    Codeforces 975C
    Codeforces 976D
    HDU 1024 Max Sum Plus Plus (DP,水题)
    HDU 1003 Max Sum(DP,水题)
  • 原文地址:https://www.cnblogs.com/Apologize/p/5764852.html
Copyright © 2011-2022 走看看