美文网首页
【iOS开发】UISegmentedControl自定义背景颜色

【iOS开发】UISegmentedControl自定义背景颜色

作者: 文刂Rn | 来源:发表于2017-01-15 15:56 被阅读551次

    在UISegmentedControl的控件中,有一个设置默认颜色的

    // The tintColor is inherited through the superview hierarchy. See UIView for more information. 
    @property(null_resettable,nonatomic,strong) UIColor *tintColor; 
    

    使用方式如下:

     [_segmentedControl setTintColor:[UIColor whiteColor]];
    
    • 设置选中时的背景色
    [_segmentedControl setBackgroundImage:[UIImage imageNamed:@"selectImg"]
                              forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    
    • 设置为选中时的背景色
    [_segmentedControl setBackgroundImage:[UIImage imageNamed:@"unSelectImg"]
                                         forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
    • 设置选中时字体颜色
     NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:RGBA(.94, .31, .18),UITextAttributeTextColor,nil];
    [_segmentedControl setTitleTextAttributes:dic forState:UIControlStateSelected];
    
    • 设置默认字体颜色
    NSDictionary *dics = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil];
    [_segmentedControl setTitleTextAttributes:dics forState:UIControlStateNormal];
    

    相关文章

      网友评论

          本文标题:【iOS开发】UISegmentedControl自定义背景颜色

          本文链接:https://www.haomeiwen.com/subject/ewoybttx.html