关于在self.navigationItem.titleView 中增加视图和改变frame的问题

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;

注:不喜勿喷!!!

你可能感兴趣的:(关于在self.navigationItem.titleView 中增加视图和改变frame的问题)