- (instancetype)initWithItems:(NSArray *)items;初始化方法胀蛮,items:傳入選項卡的選項
- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment; 設(shè)置某個選項的圖片
- (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment;設(shè)置選項卡內(nèi)容的偏移量
@property(nonatomic) NSInteger selectedSegmentIndex;設(shè)置選中的選項卡
@property(nonatomic,retain) UIColor *tintColor;設(shè)置選項卡的主題顏色似谁,(主要為字體赏淌,以及邊框顏色)
- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics 設(shè)置背景圖片稚虎,對應(yīng)狀態(tài)贤牛,顯示對應(yīng)的背景圖片
- (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state設(shè)置字體(富文本) 對應(yīng)狀態(tài)的字體溃蔫。
皆疹、
@property (strong, nonatomic) IBOutlet UISegmentedControl *segmentController;
_segmentController.tintColor = [UIColor blackColor];
// 設(shè)置UISegmentedControl選中的圖片
[segContontrol setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentSelectedBG"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
// 正常的圖片
[segContontrol setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentBG"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//設(shè)置選中文字屬性
NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName: [UIColor blackColor]};
[_segmentController setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
//設(shè)置未選中文字屬性
NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12], NSForegroundColorAttributeName: [UIColor grayColor]};
[_segmentController setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];