UIBarButtonItem with custom image and no border

前端 未结 9 680
旧巷少年郎
旧巷少年郎 2020-12-12 12:18

I want to create a UIBarButtonItem with a custom image, but I don\'t want the border that iPhone adds, as my Image has a special border.

It\'s the same as the back b

9条回答
  •  死守一世寂寞
    2020-12-12 12:49

    I found it this ways easy. It is sugested on top. "random.png" has to be in project. Just drag and drop any image.

     UIButton *a1 = [UIButton buttonWithType:UIButtonTypeCustom];
            [a1 setFrame:CGRectMake(0.0f, 0.0f, 25.0f, 25.0f)];
            [a1 addTarget:self action:@selector(randomMsg) forControlEvents:UIControlEventTouchUpInside];
            [a1 setImage:[UIImage imageNamed:@"config.png"] forState:UIControlStateNormal];
            UIBarButtonItem *random = [[UIBarButtonItem alloc] initWithCustomView:a1];
    
     //? line incomplete ?//   imageNamed:@"random.png"] style:UIBarButtonItemStylePlain target:self action:@selector(randomMsg)];
    
        self.navigationItem.rightBarButtonItem = random;
    

提交回复
热议问题