美文网首页
UISegmentedControl

UISegmentedControl

作者: 白日一山 | 来源:发表于2016-09-21 16:23 被阅读0次
    - (instancetype)initWithItems:(NSArray *)items;初始化方法,items:传入选项卡的选项
    - (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment; 设置某个选项的图片
    - (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment;设置选项卡内容的偏移量
    @property(nonatomic) NSInteger selectedSegmentIndex;设置选中的选项卡
    @property(nonatomic,retain) UIColor *tintColor;设置选项卡的主题颜色,(主要为字体,以及边框颜色)
    - (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics 设置背景图片,对应状态,显示对应的背景图片
    - (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state设置字体(富文本) 对应状态的字体。
    

     @property (strong, nonatomic) IBOutlet   UISegmentedControl *segmentController;
    
     _segmentController.tintColor = [UIColor blackColor];
    
    // 设置UISegmentedControl选中的图片 
    [segContontrol setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentSelectedBG"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; 
    // 正常的图片 
    [segContontrol setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentBG"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
    //设置选中文字属性
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName: [UIColor blackColor]};
    [_segmentController setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
    //设置未选中文字属性
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12], NSForegroundColorAttributeName: [UIColor grayColor]};
    [_segmentController setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];

    相关文章

      网友评论

          本文标题:UISegmentedControl

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