//直接获取并强转为UISegmentedControl
//除了强制转换获取还可以SB中拖线获取也是👌
UISegmentedControl *seg = (UISegmentedControl *)self.navigationItem.titleView;
//设置默认背景图片
[seg setBackgroundImage:[UIImage imageNamed:@"name_no"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//设置选中背景图片
[seg setBackgroundImage:[UIImage imageNamed:@"name_sel"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
//设置文字颜色
[seg setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
[seg setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
//设置默认颜色
[seg setTintColor:[UIColor clearColor]];
barMetrics枚举
UIBarMetricsDefault//横竖屏都显示
UIBarMetricsCompact//横屏显示,竖屏不显示
UIBarMetricsDefaultPrompt//竖屏有副标题显示 横屏有副标题不显示
UIBarMetricsCompactPrompt//竖屏有副标题不显示 横屏有副标题显示
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)