Espina
Espina

Reputation: 83

How to make the close icon (red x) on the view?

I want to do the same as mobile safari multi-page mode, a red x on the top right screenshot of previously opened page, tap it to close it.

I searched but couldn't find any. Is it a out-of-box widget in iOS or something I should custom make it?

Upvotes: 1

Views: 716

Answers (1)

Wayne Hartman
Wayne Hartman

Reputation: 18477

Create an image that is the same as the close icon (there isn't a way through public APIs to get it) and set it as the background of a UIButton. Then, add it as a subview of your page. Done.

UIButton* closeButton = [[UIButton alloc] 
                               initWithFrame:CGRectMake(0.0f, 0.0f, 25.0f, 25.0f)];
[closeButton addTarget:self 
                action:@selector(didTapCloseButton:) 
      forControlEvents:UIControlEventTouchUpInside];
[closeButton setBackgroundImage:[UIImage imageNamed:@"closeButton.png"] 
                       forState:UIControlStateNormal];

[self.pageView addSubview:button];
[closeButton release];

Upvotes: 3

Related Questions