简体   繁体   English

创建与UISearchBar取消按钮相同样式的UIButton

[英]Create UIButton same style of UISearchBar cancel button

I want to make UIButton. 我想做UIButton。 It has same style of "UISearchBar cancel button". 它具有与“ UISearchBar取消按钮”相同的样式。 I want to know style setting code of "UISearchBar cancel button". 我想知道“ UISearchBar取消按钮”的样式设置代码。

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. 我假设您想创建一个带有X的圆形按钮。

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 看一下文档: UIButton类参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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