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值來達到效果。