iPhone的stretchableImageWithLeftCapWidth只产生“D”
UIImage *aImage = [[UIImage imageNamed:@"Gray_Button.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:0];
尝试制作“玻璃药丸纽扣”。
如果图像更大……而我尝试使用它的按钮……更小,“拉伸”会做什么?
图像会“拉伸”和“收缩”吗?
我问的原因...是因为我所有的图像最终看起来都像“D”形状。
左侧是方形的...右侧是圆形的。
D 形会告诉你什么我做错了? 太多...或太少...“leftCap 设置”? 图片太大?
UIImage *aImage = [[UIImage imageNamed:@"Gray_Button.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:0];
Trying to make a "glass pill button".
What does "stretch" do if the image is bigger... and the button I'm trying to use it on... is smaller?
Does the image 'stretch' and 'shrink'?
The reason I ask... is because all my images end up look like a "D" shape.
The left side is squared-off... and the right side is rounded.
What would a D-shape tell you that I'm doing wrong?
Too much.. or too little... "leftCap setting"?
Too large an image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
leftCapWidth
和topCapHeight
均非零,则可拉伸图像将分为 9 个部分。中心部分的大小始终为 1 px,这是被拉伸的部分,例如:
要创建“玻璃药丸按钮”,您应该将圆形边框填充到上面的区域 A、B、C 和 D 中,然后将该药丸的半径提供给
leftCapWidth
和topCapHeight
。此外,可拉伸图像不可收缩。如果您尝试使用比您想要应用的按钮(或其他任何东西)更大的可拉伸图像,它们可能会被错误地渲染(尤其是在较旧的 iOS 上)。
A stretchable image is divided into 9 parts, if both
leftCapWidth
andtopCapHeight
are nonzero.The central parts are always 1 px in size, and this is the part that is stretched, for example:
To create a "glass pill button", you should fill the rounded border into the regions A, B, C and D above, and supply the radius of that pill into both the
leftCapWidth
andtopCapHeight
.Also, a stretchable image is not shrinkable. If you try to use stretchable images bigger than the buttons (or whatever else) you want to apply it to, they may be rendered incorrectly (especially on older iOSes).
stretchableImageWithLeftCapWidth 的行为与您预期的不同。我建议使用 UIView 的 contentStretch 属性来避免一些挫败感。
仅供参考,stretchableImage 的行为方式是:
另一方面,contentStretch 的行为正如您所期望的那样。该图形基本上分为 9 个部分,按照肯尼解释的方式扩展和收缩。
另外,不要忘记,无论何时拉伸视图,其 contentMode 都应设置为 UIViewContentModeScaleToFill。
stretchableImageWithLeftCapWidth does not behave as you would expect. I suggest using UIView's contentStretch property instead to save yourself some frustration.
FYI, the way stretchableImage behaves is:
contentStretch, on the other hand, behaves just as you would expect. The graphic basically gets split into 9 parts that expand AND CONTRACT the way Kenny explained.
Also, don't forget that anytime you stretch a view, its contentMode should be set to UIViewContentModeScaleToFill.