ios 导航添加多个按钮

2018-11-09  本文已影响0人  你又脸红了i

//第一个按钮

    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];

    [butaddTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];

    [butsetImage:[UIImage imageNamed:@"btn_pause"] forState:UIControlStateNormal];

    [butsizeToFit];

    UIBarButtonItem *Item = [[UIBarButtonItem alloc] initWithCustomView:but];

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

//    fixedSpaceBarButtonItem.width = 22;

    //第二个

    UIButton *but1 = [UIButton buttonWithType:UIButtonTypeCustom];

    [but1addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];

    [but1setImage:[UIImage imageNamed:@"btn_play"] forState:UIControlStateNormal];

    [but1sizeToFit];

    UIBarButtonItem *Item1 = [[UIBarButtonItem alloc] initWithCustomView:but1];

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

//    fixed.width = 22;

    //第三个

    UIButton *set2 = [UIButton buttonWithType:UIButtonTypeCustom];

    [set2addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];

    [set2setImage:[UIImage imageNamed:@"btn_play"] forState:UIControlStateNormal];

    [set2sizeToFit];

    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithCustomView:set2];

    self.navigationItem.rightBarButtonItems  =@[Item,Item1,item2];

上一篇下一篇

猜你喜欢

热点阅读