Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add iOS Close Button Icon Without Custom Image

Tags:

ios

icons

Is there a custom X or close button icon builtin to iOS7 that can be used for a close button?

like image 456
Mike Flynn Avatar asked Dec 31 '13 03:12

Mike Flynn


4 Answers

The closest built-in icon / image that looks like an X or a Close Button on iOS 7 is the UIBarButtonItemSystemStop image. Here is a link to the documentation from Apple. Below is the system image (which I image can be tinted using the iOS 7 tint parameter):

UIBarButtonItemSystemStop

You can also create your own - graphically in Photoshop or simply using text (which would fit the iOS 7 design). Just a fancied up X will do! Even a UIBarButtonItem with an "X" and then set the style to Done will give a bolded X.

Another (private) real-iOS example is from UIKit's private resources - the iAd close button. Try using an app like iOS Artwork Extractor to search for and download UIKit images. The images in UIKit are owned by Apple; so you'll need to create your own. You can use the images provided there for inspiration, and then create your own thing in Photoshop.

like image 182
Sam Spencer Avatar answered Oct 23 '22 00:10

Sam Spencer


Of course it is possible.

UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:(UIBarButtonSystemItemStop) 
                         target:self 
                         action:@selector(doneButtonTapped:)];

self.navigationItem.rightBarButtonItem = closeButton;

It gives you a built-in 'X' button as the image shows.

x button

Successful tested under Xcode 5 and iOS 7.

QUOTE FROM Sam:

Even a UIBarButtonItem with an "X" and then set the style to Done will give a bolded X.

Although it works, the visual effect is ugly and users will feel it.

like image 23
Kaihua Avatar answered Oct 23 '22 00:10

Kaihua


The letter X is not visually appealing but the symbol × should work pretty well.

let buttonItem = UIBarButtonItem(title: "×", style: UIBarButtonItemStyle.Plain, target: nil, action: Selector(""))
let font = UIFont.systemFontOfSize(40)
buttonItem.setTitleTextAttributes([NSFontAttributeName: font], forState: .Normal)

Only I can't get the vertical alignment right.. Not even with:

buttonItem.setTitlePositionAdjustment(UIOffsetMake(0, 10), forBarMetrics: .Default)

enter image description here

like image 7
Koen. Avatar answered Oct 23 '22 02:10

Koen.


use UIBarButtonItem and set it's style UIBarButtonSystemItemStop can give you an X button. but i'm not sure if this is what you want.

like image 5
johnMa Avatar answered Oct 23 '22 01:10

johnMa