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

时间:2023-01-16 20:08:15
    //个性推荐 歌单 主播电台 排行榜
NSArray* promoteArray=@[@"个性推荐",@"歌单",@"主播电台",@"排行榜"];
UISegmentedControl* promoteSgement=[[UISegmentedControl alloc]initWithItems:promoteArray];
promoteSgement.frame=CGRectMake(, , screenWidth, );
[promoteSgement setSelectedSegmentIndex:];//默认选择第一个
promoteSgement.tintColor = [UIColor clearColor];//去掉颜色 现在整个segment都看不见
NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:],NSForegroundColorAttributeName:[UIColor colorWithRed:/256.0 green:/256.0 blue:/256.0 alpha:]};
[promoteSgement setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置选择时文字的属性
NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:],NSForegroundColorAttributeName: [UIColor blackColor]};
[promoteSgement setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];//设置未选择时文字的属性
[self.view addSubview:promoteSgement];