xcode - 想要将 UIbutton 更改为我选择的图像
问题描述
UIButton *openButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
openButton.frame = CGRectMake((main.frame.size.width/2)-15, (main.frame.size.height/2)+75, 30, 30);
openButton.backgroundColor = [UIColor clearColor];
openButton.layer.cornerRadius = 16;
openButton.layer.borderWidth = 2;
openButton.layer.borderColor = themeColor.CGColor;
[openButton addTarget:self action:@selector(wasDragged:withEvent:)
forControlEvents:UIControlEventTouchDragInside];
[openButton addTarget:self action:@selector(showMenu)
forControlEvents:UIControlEventTouchDownRepeat];
这是我的打开按钮的代码,它已经在 mod 菜单中实现了,但我真的想将其更改为示例图像而不是圆形。我尝试将其更改为 UIImage,但由于我是编码新手,因此我不确定如何正确执行。
解决方案
请试试这个:
yourBtn.setImage(UIImage(named: "ImgName"), for: .normal)
请转换为目标c。setImage
是 UIButton 的一个属性,用于图像设置。
它可能会帮助你。谢谢
推荐阅读
- python - docker中的python脚本在卷中创建锁定文件
- opencart - Opencart 结帐页面中未显示税款
- eclipse - 如何从命令行导入现有的eclipse项目
- python - 如何从python中的异常消息中删除类名
- javascript - 谷歌地图没有在java脚本中第二次加载
- c# - 我无法使用 StreamWriter 类创建新的 .txt 文件
- android - getActivity().runOnUiThreadnew Runnable() 中的错误
- javascript - 在 MAC Safari 中打印 html 页面时重复页眉/页脚
- ios - 分享 MTLTexture
- testing - 如何在 selenium web driver-java 中处理图像验证码