iOS 控件

自定义导航栏左边按钮的位置靠左问题,右边按钮的位置靠右的问题

2017-06-03  本文已影响77人  wodeph

UIButton    *leftBtn = [[UIButton  alloc]    initWithFrame:CGRectMake(-10,0,scrrenW*0.05,44)];

[leftBtn    setBackgroundImage:[UIImage   imageNamed:@"btnBack"]   forState:UIControlStateNormal];

leftBtn.contentHorizontalAlignment   = UIControlContentHorizontalAlignmentLeft;

[leftBtn   setTitleColor:totalColor    forState:UIControlStateNormal];

leftBtn.titleLabel.font= [UIFont    systemFontOfSize:40];

[leftBtn   addTarget:self action:@selector(backClick)   forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem   *item = [[UIBarButton   Itemalloc]   initWithCustomView:leftBtn];

UIBarButtonItem   *negativeSpacer1 = [[UIBarButtonItem      alloc]    initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace

    target:nil    action:nil];

negativeSpacer1.width= -20;//这个数值可以根据情况自由变化

self.navigationItem.leftBarButtonItems=@[negativeSpacer, item];// 解决左边按钮靠左的问题,****右边按钮可以用同样的方法解决

注:不喜勿喷!!!

上一篇 下一篇

猜你喜欢

热点阅读