UISegment 设置样式(背景颜色,字体颜色)

2019-03-08  本文已影响0人  原味丿丿咖啡Vitas
    self.segment.tintColor = [UIColor colorWithRGB:0xE8985E];
    self.segment.layer.cornerRadius = 17.0;
    self.segment.clipsToBounds = YES;
    [self.segment setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRGB:0xDEDEDE]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [self.segment setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRGB:0xE8985E]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    NSDictionary *normalDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRGB:0x999999],NSForegroundColorAttributeName,nil];
    [self.segment setTitleTextAttributes:normalDic forState:UIControlStateNormal];
    NSDictionary *selectDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil];
    [self.segment setTitleTextAttributes:selectDic forState:UIControlStateSelected];

效果如下

image.png
上一篇下一篇

猜你喜欢

热点阅读