码迷,mamicode.com
首页 > 其他好文 > 详细

创建一个没有边框的并添加自定义文字的UISegmentedControl

时间:2015-12-02 16:11:50      阅读:418      评论:0      收藏:0      [点我收藏+]

标签:

    //个性推荐 歌单 主播电台 排行榜

    NSArray* promoteArray=@[@"个性推荐",@"歌单",@"主播电台",@"排行榜"];

    UISegmentedControl* promoteSgement=[[UISegmentedControl alloc]initWithItems:promoteArray];

    promoteSgement.frame=CGRectMake(0, 64, screenWidth, 40);

    [promoteSgement setSelectedSegmentIndex:0];//默认选择第一个

    promoteSgement.tintColor = [UIColor clearColor];//去掉颜色 现在整个segment都看不见

    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor colorWithRed:212/256.0 green:21/256.0 blue:10/256.0 alpha:1]};

    [promoteSgement setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置选择时文字的属性

    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName: [UIColor blackColor]};

    [promoteSgement setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];//设置未选择时文字的属性

    [self.view addSubview:promoteSgement];

创建一个没有边框的并添加自定义文字的UISegmentedControl

标签:

原文地址:http://www.cnblogs.com/death3721/p/5013268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!