简体   繁体   中英

Create UIButton same style of UISearchBar cancel button

I want to make UIButton. It has same style of "UISearchBar cancel button". I want to know style setting code of "UISearchBar cancel button".

Please teach me.

cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelButton setFrame:CGRectMake(0,0,100,30)];

I assume you want to create a round button with a X inside it.

You can't simply set a style on the button to achieve this. You should create a button and set your custom image.

UIImage *image = [UIImage imageNamed:@"yourImage"];
[cancelbutton setImage:image forState:UIControlStateNormal];

Take a look at the documentation: UIButton Class Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM