【问题标题】:How to make image insets for image within UISegmentedControl?如何在 UISegmentedControl 中为图像制作图像插图?
【发布时间】:2019-01-14 12:01:43
【问题描述】:

我有带有图像的 UISegmented 控件 - 以便能够设置背景色调。这是通过viewDidLoad中的代码添加到导航栏的:

UISegmentedControl *myCustomButton = [[UISegmentedControl alloc] initWithItems:
                    [NSArray arrayWithObjects:[UIImage imageNamed:@"spiral"],nil]];

[myCustomButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[myCustomButton setTintColor:[UIColor blackColor]];

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc]
                                    initWithCustomView:myCustomButton];
self.navigationItem.rightBarButtonItem = segmentBarItem;

问题是按钮内的图像被拉伸了,所以我想使用图像插入,但我该如何称呼它们代码?

我试过这个:

[self.navigationItem.rightBarButtonItem setImageInsets:UIEdgeInsetsMake(5, 5, 5, 5)];

但它不会做任何可见的事情。

【问题讨论】:

  • 我发现在段文本的左右添加空格就可以了。

标签: iphone cocoa-touch ios uisegmentedcontrol


【解决方案1】:

我不确定是否有一种简单的编程方式可以做到这一点。我所做的只是在 Photoshop(或任何图像编辑器)中制作具有透明背景的 png 图像,并使其适合,以便您的图像垂直适合按钮,并且大小恰好适合您的按钮。制作图像需要一些工作,但通常一旦设置好屏幕布局,您就不会更改按钮大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 2011-03-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多