选择卡

运用seg实现选项卡 效果类似于

13A76D1A-FF66-4309-8596-1316FC1714B2.png

代码如下

#define     kVheadHeight            40
#define     kVLineRedMarkHeight     2
#define     kVLineRedMarkWidth      20
#define     kVLineRedMarkOriginX   (((SCREEN_WIDTH/2)-kVLineRedMarkWidth)/2)
#define     kVLineRedMarkOriginY    (kVheadHeight-2)

@property (nonatomic, strong) UIView             *vHeadBg;
@property (nonatomic, strong) UISegmentedControl *segChoose;
@property (nonatomic, strong) UIView             *vlineCenterSep;
@property (nonatomic, strong) UIView             *vLineRedMark;

//基本控件封装成一句话了 UIKitFactory
_vHeadBg = [UIKitFactory createViewWithFrame:CGRectMake(0,0, SCREEN_WIDTH, 40) backgroundColor:Color_White superView:self.view];

 _segChoose = [[UISegmentedControl alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
  _segChoose.backgroundColor =  Color_White;
  [_segChoose setTintColor:Color_White];
   _segChoose.layer.borderColor = Color_White.CGColor;
 NSArray *arrTitle = @[@"推荐",@"关注"];
for (int i = 0; i < arrTitle.count; i ++) {
    [_segChoose insertSegmentWithTitle:arrTitle[i] atIndex:i animated:NO];
}
[_segChoose setTitleTextAttributes:@{NSFontAttributeName:Font_Moments_SegTitle,NSForegroundColorAttributeName:Color_Moments_SegNormal} forState:UIControlStateNormal];
[_segChoose setTitleTextAttributes:@{NSFontAttributeName:Font_Moments_SegTitle,NSForegroundColorAttributeName:Color_Moments_ColorRed} forState:UIControlStateSelected];
[_segChoose addTarget:self action:@selector(segmentedValueChanged:
                                            ) forControlEvents:UIControlEventValueChanged];
[_vHeadBg addSubview:_segChoose];
_segChoose.selectedSegmentIndex = 0;


_vLineRedMark = [UIKitFactory createViewWithFrame:CGRectMake(kVLineRedMarkOriginX,kVLineRedMarkOriginY, kVLineRedMarkWidth, kVLineRedMarkHeight) backgroundColor:Color_Moments_ColorRed superView:_vHeadBg];
_vlineCenterSep = [UIKitFactory createViewWithFrame:CGRectMake(0, 0, 0.5, 20) backgroundColor:Color_LineColor superView:_vHeadBg];
_vlineCenterSep.center = _vHeadBg.center;

[UIKitFactory createViewWithFrame:CGRectMake(0,kVheadHeight-0.5, SCREEN_WIDTH, 0.5) backgroundColor:Color_LineColor superView:_vHeadBg];

seg 事件处理
- (void)segmentedValueChanged:(UISegmentedControl *)segChoose{
[UIView animateWithDuration:0.3f animations:^{
CGRect rect = _vLineRedMark.frame;
rect.origin.x = segChoose.selectedSegmentIndex *(SCREEN_WIDTH/2) + kVLineRedMarkOriginX;
_vLineRedMark.frame = rect;
}];

 //刷新数据
   [_tbvMomentsMain.mj_header beginRefreshing];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,234评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 15,451评论 4 61
  • 生活里,我们因为无意间的几句口误,就成了搞笑高手,来看看下面几句话,笑一笑吧: 二楞子在市场上看见了老舅,激动地冲...
    樱子先生阅读 478评论 7 5
  • 我是1976年生人,那年中国大事不断,其中之一就是发生了唐山大地震。 当然,我那时候还小,对此毫无印象,只是在母亲...
    蔡立鹏阅读 652评论 0 2
  • --------- 看不见是窗户 听不见是太阳 触不到是星星 嗅不见是月亮 你是整个世界 全部宝贵
    雨的飘阅读 220评论 4 5

友情链接更多精彩内容