美文网首页iOS 控件
关于在self.navigationItem.titleView

关于在self.navigationItem.titleView

作者: wodeph | 来源:发表于2017-06-03 16:31 被阅读207次

    NSArray   *segeArray = [NSArray arrayWithObjects:@"PHOTOS",@"VIDEOS",nil];

    UISegmentedControl   *segmentCtr = [[UISegmentedControl alloc]     initWithItems:segeArray];

    segmentCtr.selectedSegmentIndex=0;

    segmentCtr.frame=CGRectMake(0,5,scrrenW*0.5,37);

    segmentCtr.tintColor= [UIColor   whiteColor];

    [segmentCtr setTitleTextAttributes:@{NSForegroundColorAttributeName:totalColor,NSFontAttributeName:[UIFont systemFontOfSize:24]}     forState:UIControlStateSelected];

    //未选中的颜色

    [segmentCtr setTitleTextAttributes:@{NSForegroundColorAttributeName:totalColor,NSFontAttributeName:[UIFont systemFontOfSize:24]}   forState:UIControlStateNormal];

    [segmentCtr addTarget:selfaction:@selector(segmentValueChanged:)  forControlEvents:UIControlEventValueChanged];

    UIView   * titleView = [[UIView alloc]   initWithFrame:CGRectMake(scrrenW*0.35,0,scrrenW*0.5,44)];// 改变titleView的frame

    [titleView addSubview:segmentCtr];//  把你想要加进去的View加入到titleView

    self.navigationItem.titleView= titleView;

    注:不喜勿喷!!!

    相关文章

      网友评论

        本文标题:关于在self.navigationItem.titleView

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