在 rightbarbuttonitem 中使用方形图像?
我想要方形图像周围有常规按钮形状,所以我选择了 initWithImage:Style:Target:Action。问题是,它然后拉伸我的图像以适应宽按钮,而这根本不是我想要的。我如何让它把我的图像放在那里而不拉伸?我该如何改变矩形的宽度?
I want the regular button shape around my square image, so I went for initWithImage:Style:Target:Action. The problem is, it then stretches my image to fit a wide button, and this isn't what i want at all. How do i make it put my image there without stretching? And how would i change the rectangle width too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否可以将图像添加到栏按钮上,以便它看起来有轮廓。我确实知道您可以相当轻松地添加自己的自定义视图,而不会拉伸图像。基本上,您所要做的就是创建一个用图像初始化的 imageView,然后创建一个栏按钮项并向其中添加自定义视图。
然后您只需将按钮设置在您想要的位置即可。同样,这不会为您提供按钮背景,因此最好创建一个带有按钮背景的图像(可能将现有图像Photoshop到按钮上,然后保存新图像并使用该图像)
I'm not sure if you can add an image onto a bar button so it looks outlined. I do know that you can add you own custom view fairly easily that doesn't stretch the image. Basically, all you have to do is create an imageView initialized with your image, then create a bar button item and add the custom view to it.
Then you just have to set the button where you want it. Again, this won't give you a button background, so it might be best to create an image with a button background (possibly photoshop your existing image on a button, then save that new image and use that one)
您可以尝试调整 UIBarButtonItem 的宽度。
You might try adjusting the width of the UIBarButtonItem.