2011-01-31 35 views
0

问候, 我有UISegmented控制与图像 - 可以设置背景色调。这是通过代码viewDidLoad中添加导航栏:如何在UISegmentedControl中为图像制作图像插图?

 
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)]; 但它没有做任何可见的事情。

+0

我发现在段文本的左侧和右侧添加空格时效果很好。 – titaniumdecoy 2011-05-27 20:39:37

回答

2

我不确定有一个简单的编程方式来做到这一点。我所做的只是在Photoshop中使用透明背景制作png图像(或任何图像编辑器)并使它们合适,以便图像垂直放置在按钮中,并且尺寸适合您的按钮。制作图像是一项工作,但通常在设置好屏幕布局后,您不会改变按钮大小。