1.UISegmentedControl字体
UISegmentedControl *segC =[[UISegmentedControl alloc]initWithItems:@[@"传感器",@"床垫"]; segC.layer.cornerRadius=5; segC.tintColor = btnBackgColor; //字体大小 UIFont *font = [UIFont boldSystemFontOfSize:14]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; [segC setTitleTextAttributes:attributes forState:UIControlStateNormal]; //字体颜色 segC.layer.borderWidth = 2; segC.layer.borderColor = [btnBackgColor CGColor]; //默认选择 [segC setSelectedSegmentIndex:0]; [segC addTarget:self action:@selector(btnChanged:) forControlEvents:UIControlEventValueChanged]; //添加到界面,并肯定大小位置 [self.view addSubview:segC]; [segC mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(segC.superview).with.offset(statusNavigationBarH+marginL); make.left.equalTo(segC.superview).with.offset(marginL); make.centerX.equalTo(segC.superview); make.height.mas_equalTo(40); }]; -(void)btnChanged:(UISegmentedControl *)segc{ if (segc.selectedSegmentIndex == 0) { Log(@"传感器"); } else { Log(@"床垫"); } }