码迷,mamicode.com
首页 > 移动开发 > 详细

ios UISegmentedControl的定制

时间:2018-04-19 12:01:12      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:nonatomic   效果   nts   white   hang   dict   att   index   com   

先看效果图

技术分享图片

代码:

@property (nonatomic, strong) UISegmentedControl *segmentedControl;


-(void)createSegMentController{
    NSArray *segmentedArray = [NSArray arrayWithObjects:@"通知",@"评论",nil];
        UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
    segmentedControl.frame = CGRectMake(0, 0, 190, 22);
    segmentedControl.selectedSegmentIndex = 0;
    segmentedControl.tintColor = UIColorFromRGB(0x3E4759);
    segmentedControl.backgroundColor = [UIColor whiteColor];
    segmentedControl.layer.masksToBounds = YES;
    segmentedControl.layer.cornerRadius = 12;
    segmentedControl.layer.borderWidth = 0.5;
    segmentedControl.layer.borderColor = UIColorFromRGB(0x3E4759).CGColor;
    NSDictionary *dicnor = [NSDictionary dictionaryWithObjectsAndKeys:UIColorFromRGB(0x3E4759),NSForegroundColorAttributeName,[UIFont systemFontOfSize:14],NSFontAttributeName, nil];
    [segmentedControl setTitleTextAttributes:dicnor forState:UIControlStateNormal];
    NSDictionary *dicselect = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:14],NSFontAttributeName, nil];
    [segmentedControl setTitleTextAttributes:dicselect forState:UIControlStateSelected];

    [segmentedControl addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged];
    [self.navigationItem setTitleView:segmentedControl];
    self.segmentedControl = segmentedControl;

}

-(void)indexDidChangeForSegmentedControl:(UISegmentedControl *)sender
{
    NSInteger selecIndex = sender.selectedSegmentIndex;
    if (selecIndex == 0) {
        sender.selectedSegmentIndex = 0;
       
    } else {
        sender.selectedSegmentIndex = 1;
       
    }
}

 

ios UISegmentedControl的定制

标签:nonatomic   效果   nts   white   hang   dict   att   index   com   

原文地址:https://www.cnblogs.com/qiyiyifan/p/8880723.html

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