Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically draw back button with arrow?

Usually when you use a UINavigationController you get a back button that has an arrow on the left side of it. The thing is I am not using a UINavigationController so thats why I am asking. Anyway here is a picture:

enter image description here

So far I have a regular UIBarButtonItem which currently is just square without that arrow on the left side of it.

Is there a way to make a button that has an arrow on the left side like that and add it to my UINavigationBar? I have also looked around and it seems that UIButton type 101 is undocumented and will cause a rejection. I need a solution that will be accepted!

like image 471
SimplyKiwi Avatar asked May 26 '26 01:05

SimplyKiwi


1 Answers

You can give the button a background image that makes it look like the native angled button:

testButton = [[UIButton alloc] initWithFrame:CGRectMake(80, 30, 160, 44)];
[testButton setTitle:@"Test Button" forState:UIControlStateNormal];
UIImage *buttonImage = [[UIImage imageNamed:@"angledButton"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
[testButton addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];
[testButton setBackgroundImage:buttonImage forState:UIControlStateNormal];

You might need to tweak that, but it's in the right direction I believe.

like image 129
woz Avatar answered May 27 '26 14:05

woz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!