gpt4 book ai didi

ios - 带有左+右大写和中间模式的 UIButton

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:00 24 4
gpt4 key购买 nike

我怎样才能创建一个 UIButton 背景图片由以下部分组成:

  1. 一个固定的
  2. 一个固定的
  3. 一些中间图像一个接一个地放置以填充所有可用空间

就像下面的例子一样?

UIButton

编辑: 我没有意识到在中心没有 N 个重复图像,只有一个拉伸(stretch)图像。查看已接受的答案。

最佳答案

据我所知,这是不可能的。你可以做的是拉伸(stretch)一个图像,但你不能添加 n 个中间图像。

中间添加一张可伸缩图片的代码是

//Create an image - Where UIEdgeInsets is in top left bottom right
UIImage* buttonImage = [[UIImage imageNamed:@"button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];

// Create a custom buttom
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(0, 0, 100, buttonImage.size.height);
[myButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[myButton setTitle:@"Button" forState:UIControlStateNormal];

//Add it to view - if it is a view controller self.view
[self addView:myButton];

来自 Apple 的 UIImage Class Reference :

"resizableImageWithCapInsets:

You use this method to add cap insets to an image or to change the existing cap insets of an image. [...] During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the pixel area not covered by the cap in each direction is tiled, left-to-right and top-to-bottom, to resize the image." [emphasis added]

您可以在 http://mobiledevelopertips.com/user-interface/ios-5-uiimage-and-resizableimagewithcapinsets.html 阅读更多相关信息

关于ios - 带有左+右大写和中间模式的 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11824603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com