美文网首页
self.edgesForExtendedLayout

self.edgesForExtendedLayout

作者: 天空没有太阳 | 来源:发表于2016-02-23 18:03 被阅读1288次

    https://github.com/HeshamMegid/HMSegmentedControl
    HMSegmentedControl中,发现如下一行代码

    self.edgesForExtendedLayout = UIRectEdgeNone;
    

    查了一下用法:
    http://blog.sina.com.cn/s/blog_6291e42d0101f6b0.html

        self.title = @"HMSegmentedControl Demo";
        self.view.backgroundColor = [UIColor whiteColor];
        self.edgesForExtendedLayout = UIRectEdgeNone;
        CGFloat viewWidth = CGRectGetWidth(self.view.frame);
        // Minimum code required to use the segmented control with the default styling.
        HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"Trending", @"News", @"Library"]];
        segmentedControl.frame = CGRectMake(0, 20, viewWidth, 40);
        segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
        [segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:segmentedControl];
    
        self.title = @"HMSegmentedControl Demo";
        self.view.backgroundColor = [UIColor whiteColor];
        // 注释zhe
        //self.edgesForExtendedLayout = UIRectEdgeNone;
        CGFloat viewWidth = CGRectGetWidth(self.view.frame);
        // Minimum code required to use the segmented control with the default styling.
        HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"Trending", @"News", @"Library"]];
        segmentedControl.frame = CGRectMake(0, 84, viewWidth, 40);
        segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
        [segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:segmentedControl];
    

    两者效果图一样,如下图


    没有遇到该方法之前,我之前用的是第二种方式,通过添加y值来达到效果。

    相关文章

      网友评论

          本文标题:self.edgesForExtendedLayout

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