How to adjust UIToolBar left and right padding

后端 未结 10 548
自闭症患者
自闭症患者 2020-12-02 05:05

I create one UIToolbar with code and another with interface builder. But, found out the two toolbar having different left and right padding which shown below:

From I

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 05:50

    Finally for having customized background image for the UIBarButtonItem and to accomodate the alignment, I have abandon UIBarButtonItem and adding UIButton manually.

    UIImage *buttonImage = [[UIImage imageNamed:@"button.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0];
    UIButton *btnTest = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnTest setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [btnTest setTitle:@"Back" forState:UIControlStateNormal];   
    [btnTest.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];  
    [btnTest setBackgroundImage:[imgToolbarButton stretchableImageWithLeftCapWidth:5 topCapHeight:0]  forState:UIControlStateNormal];
    [btnTest addTarget:self action:@selector(clearDateEdit:) forControlEvents:UIControlEventTouchUpInside];
    btnTest.frame = CGRectMake(0.0, 0.0, 50, 30);
    [self.toolbar addSubview:btnTest];
    [btnTestItem release];
    

提交回复
热议问题