我有一个uibarbuttonitem,但我使用initwithcustomview初始化它。我想用图像改变它的背景,但我不知道该怎么做。我正在使用setBackground方法,就像这样
NSArray *segmentText = [segmentTextMutable copy];
UIImage *image = [[[UIImage alloc] init] autorelease];
image = [UIImage imageNamed:@"bunga.jpg"];
_docSegmentedControl = [[UISegmentedControl alloc] initWithItems:segmentText];
_docSegmentedControl.autoresizingMask = UIViewAutoresizingFlexibleHeight;
_docSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled;
[_docSegmentedControl addTarget:self action:@selector(docSegmentAction:) forControlEvents:UIControlEventValueChanged];
[_docSegmentedControl setBackgroundColor:[UIColor colorWithPatternImage:image]];
但是uibarbuttonitem仍然没有显示图像,它只是改变了分段控制背景,而不是按钮。 有人可以帮帮我吗?
答案 0 :(得分:0)
也许您想要更改色调(@property(非原子,保留)UIColor * tintColor),因为UISegmentedControl没有背景色(因为它从UIView继承它并不意味着它使用它)