UISegmentedControl選擇控件

-(void)Uiconfig{

NSArray*arr = [[NSArrayalloc]initWithObjects:@"學(xué)生",@"老師",nil];

//先創(chuàng)建一個數(shù)組用于設(shè)置標(biāo)題

UISegmentedControl*segment = [[UISegmentedControlalloc]initWithItems:arr];

//在沒有設(shè)置[segment setApportionsSegmentWidthsByContent:YES]時(shí),每個的寬度按segment的寬度平分

[segmentsetTintColor:[UIColorcolorWithHexString:@"#ff6121"]];//設(shè)置segments的顏色

segment.selectedSegmentIndex=0;

segment.frame=CGRectMake(0,0,100,30);

self.navigationItem.titleView= segment;

[segmentaddTarget:selfaction:@selector(change:)forControlEvents:UIControlEventValueChanged];

//當(dāng)選中不同的segment時(shí),會執(zhí)行change:方法

//設(shè)置frame

}

-(void)change:(id)sender{

UISegmentedControl* control = (UISegmentedControl*)sender;

switch(control.selectedSegmentIndex) {

case0:

DLog(@"學(xué)生");

break;

case1:

DLog(@"老師");

break;

default:

break;

}

效果如下


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容