1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| NSArray *subjectArray = [[NSArray alloc]initWithObjects:@"英语",@"语文",@"数学",nil];
UISegmentedControl *subjectSegmented = [[UISegmentedControl alloc]initWithItems:subjectArray]; subjectSegmented.frame = CGRectMake(0, 0, DF_WIDTH/2, 44); subjectSegmented.segmentedControlStyle = UISegmentedControlStylePlain; for(int i=0; i<[subjectArray count]; i++){ if([self.subject isEqualToString:self.subjectArray[i]]){ subjectSegmented.selectedSegmentIndex = i; break; } } self.navigationview.tintColor = [UIColor colorWithHexString:@"#ff393a"]; [self.navigationview addSubview:self.subjectSegmented]; [subjectSegmented addTarget:self action:@selector(changeSubject:) forControlEvents:UIControlEventValueChanged]; [subjectSegmented mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.navigationview); make.centerYWithinMargins.equalTo(self.navigationview).with.offset(padding.top); }];
|