премахване на място под UITabBarItem?

как да намаля разстоянието между двата елемента?

моят код:

-(void)setupRightMenuButton{
    filtro = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon-filtro-bar"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonFilter)];
    busca = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon-busca"] style:UIBarButtonItemStylePlain target:self action:@selector(moveToSearchView)];

    filtro.tintColor = [UIColor whiteColor];
    busca.tintColor = [UIColor whiteColor];

    filtro.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
    busca.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:busca, filtro, nil] animated:YES];
}

Моят изгледDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupLeftMenuButton];

    [self.navigationController.navigationBar setBarTintColor: [UIColor colorWithRed:0.49 green:0.075 blue:0.082 alpha:1]]; /*#7d1315*/
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
    [self setupRightMenuButton];
    self.title = @"Músicas";

}

Опитах да използвам filtro.imageInsets = UIEdgeInsetsMake (6, 0, -6, 0);, но не се получи


person Felipe Xavier    schedule 10.09.2015    source източник
comment
добавили ли сте някакво разстояние между тези две?   -  person Teja Nandamuri    schedule 10.09.2015
comment
опитайте да добавите бутони към лентата за навигация, вместо да правите setRightBarButtonItems   -  person Teja Nandamuri    schedule 10.09.2015
comment
опитвали ли сте да промените стойността на отместването в UIOffsetMake(0, -60)? Не съм сигурен защо давате стойност като -60   -  person Teja Nandamuri    schedule 10.09.2015


Отговори (2)


Опитайте да добавите бутони по този начин:

    UIButton *but1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    UIView *but1View = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [but1View addSubview:but1];
    UIBarButtonItem *rightButton1 = [[UIBarButtonItem alloc] initWithCustomView:but1View];

    UIButton *but2 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    UIView *but2View = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [but2View addSubview:but2];
    UIBarButtonItem *rightButton2 = [[UIBarButtonItem alloc] initWithCustomView:but2View];

       self.navigationItem.rightBarButtonItems=@[ rightButton,rightButton2];

трябва да споменете позициите на x и y за двата UIView като къде искате вашите бутони в лентата за навигация.

person Teja Nandamuri    schedule 10.09.2015
comment
можете да добавите изображението към бутоните. Не го споменах в отговора - person Teja Nandamuri; 10.09.2015
comment
необходимо е бутоните да останат тези, които използвам. тогава решението няма да работи - person Felipe Xavier; 10.09.2015
comment
съжалявам, че не разбрах какво казахте. Какво имаш предвид под остават бутони? - person Teja Nandamuri; 10.09.2015
comment
Не можете да добавяте бутони към uibarbutton, ние можем да добавяме само изгледи към uibarbuttonitem. Така че добавяме добавяне на нашите бутони за преглед и добавяме изглед към елемента бутон на лентата - person Teja Nandamuri; 11.09.2015

Този код работи за мен. Опитайте да създадете бутон, след това задайте изображението към него и задайте рамката на бутоните.

let button: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
let image = UIImage(named: "your_image")!
button.setImage(image , forState: UIControlState.Normal)
// optional -------------
button.addTarget(self, action: "your_function", forControlEvents: UIControlEvents.TouchUpInside)
// ------------
button.frame = CGRectMake(0, 0, image.width, image.height)
let barButton = UIBarButtonItem(customView: button)

Създайте колкото искате barButtons и след това ги добавете към navigationItem:

self.navigationItem.setRightBarButtonItems([barBtn1, barBtn2], animated: false)
person mkz    schedule 10.09.2015