I have to click on done button to dismiss modalview programmatically. I think UIButton is better than UIBarButtonItem to add UIControlEventsTouchupInside.
But with UIButton I’m confused what buttontype should use.
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:@selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(dismissViewaction:)] autorelease];
You will most likely want to use
UIButtonTypeRoundedRectorUIButtonTypeCustomWith the custom type, you can add images for display.
You can try “stealing” these images from the
UIBarButtonItem(image property defined inUIBarItem) and making the custom button look like theUIBarButtonSystemItemDonebuttonThings to look out for. When setting an image for a UIButton, it does not scale to the size of the button according to
contentModeproperty. If you want the image to follow the rules of thecontentModeproperty, usesetBackgroundImage: forState:instead.