美文网首页
导航栏按钮的偏移

导航栏按钮的偏移

作者: 碧海云天V | 来源:发表于2017-11-16 17:46 被阅读22次

Demo

不多说,直接上

1510820203164.jpg

代码也很简单

    UIButton *settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //修改按钮向右偏移30 point
    [settingButton setFrame:CGRectMake(20.0, 0.0, 44.0, 44.0)];
    [settingButton setTitle:@"测试" forState:0];
    [settingButton  setTitleColor:[UIColor blueColor] forState:0];
    //修改方法
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 44.0, 44.0)];
    view.backgroundColor = [UIColor redColor];
    [view addSubview:settingButton];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    self.navigationItem.rightBarButtonItem = rightItem;

相关文章

网友评论

      本文标题:导航栏按钮的偏移

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