iOS 控件

关于在self.navigationItem.titleView

2017-06-03  本文已影响207人  wodeph

NSArray   *segeArray = [NSArray arrayWithObjects:@"PHOTOS",@"VIDEOS",nil];

UISegmentedControl   *segmentCtr = [[UISegmentedControl alloc]     initWithItems:segeArray];

segmentCtr.selectedSegmentIndex=0;

segmentCtr.frame=CGRectMake(0,5,scrrenW*0.5,37);

segmentCtr.tintColor= [UIColor   whiteColor];

[segmentCtr setTitleTextAttributes:@{NSForegroundColorAttributeName:totalColor,NSFontAttributeName:[UIFont systemFontOfSize:24]}     forState:UIControlStateSelected];

//未选中的颜色

[segmentCtr setTitleTextAttributes:@{NSForegroundColorAttributeName:totalColor,NSFontAttributeName:[UIFont systemFontOfSize:24]}   forState:UIControlStateNormal];

[segmentCtr addTarget:selfaction:@selector(segmentValueChanged:)  forControlEvents:UIControlEventValueChanged];

UIView   * titleView = [[UIView alloc]   initWithFrame:CGRectMake(scrrenW*0.35,0,scrrenW*0.5,44)];// 改变titleView的frame

[titleView addSubview:segmentCtr];//  把你想要加进去的View加入到titleView

self.navigationItem.titleView= titleView;

注:不喜勿喷!!!

上一篇下一篇

猜你喜欢

热点阅读