利用layer设置背景图片以及NSForegroundColorAttributeName设置颜色


@property (weak, nonatomic) IBOutlet UISegmentedControl *Sgment;

@end

@implementation ArenaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置控制器view的背景图片
    self.view.layer.contents = (__bridge id)([UIImage imageNamed:@"NLArenaBackground"].CGImage);

    //设置segument普通状态下的的背景图片
    
    [self.Sgment setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentBG"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
    //设置segument选中状态下的的背景图片
    [self.Sgment setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentSelectedBG"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

    //设置segument的文字颜色
    NSDictionary *attri = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
    //默认情况下
    [self.Sgment setTitleTextAttributes:attri forState:UIControlStateNormal];
    //选中情况下
    [self.Sgment setTitleTextAttributes:attri forState:UIControlStateSelected];


}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM