0
我的自定義UISegmented控件具有[每個州的背景圖像]。 如何在圖片上方添加文字[對於每種狀態,這意味着當索引0將被選中時,我將擁有特定的顏色和字體]?將背景圖像上方的文字添加到uiswitch
這裏是我的UISegmented控制看起來像:
UISegmentedControl *customUISC=[[UISegmentedControl alloc] initWithItems:[[[NSMutableArray alloc] initWithObjects:@"ON",@"OFF",nil] autorelease]];
[customUISC setFrame:CGRectMake(11,14,298,28)];
customUISC.selectedSegmentIndex=0;
customUISC.segmentedControlStyle=UISegmentedControlStyleBar;
[customUISC setImage:[UIImage imageNamed:@"FirstTabActive.png"] forSegmentAtIndex:0];
[customUISC setImage:[UIImage imageNamed:@"SecondTab.png"] forSegmentAtIndex:1];
[customUISC addTarget:self action:@selector(checkOnOffState:) forControlEvents:UIControlEventValueChanged];
和checkOnOffState方法是這樣的:
-(IBAction)checkOnOffState:(id)sender{
UISegmentedControl *iSeg=(UISegmentedControl *)sender;
if(iSeg.selectedSegmentIndex==0){
[iSeg setImage:[UIImage imageNamed:@"FirstTabActive.png"] forSegmentAtIndex:0];
[iSeg setImage:[UIImage imageNamed:@"SecondTab.png"] forSegmentAtIndex:1];
}
else {
[iSeg setImage:[UIImage imageNamed:@"FirstTab.png"] forSegmentAtIndex:0];
[iSeg setImage:[UIImage imageNamed:@"SecondTabActive.png"] forSegmentAtIndex:1];
}
}
@Job W 09:我已經嘗試使用UILabel將文本添加爲子視圖,但將其置於圖像下方... –