利用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