UIButton as UINavigationbar button

后端 未结 2 1826
甜味超标
甜味超标 2020-12-29 14:29

I have a Tab bar application. and in one of the tab bars I have a navigation contorller. Im trying to set a UIButton with an image as the right button the navigation bar.

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 14:56

    I ended up doing this

        UIButton *refreshButton = [[UIButton alloc] initWithFrame:CGRectMake(292, 9, 27, 27)];
        [refreshButton setImage:[UIImage imageNamed:@"refresh_icon.png"] forState:UIControlStateNormal];
        [refreshButton addTarget:self action:@selector(refresh) forControlEvents:UIControlEventTouchUpInside];
        [self.navigationController.navigationBar addSubview:refreshButton];
        [refreshButton release];
    

    It works fine now but I am not really sure if this is the right way of doing it.

提交回复
热议问题