iOS实现左右可滑动的选择条实例代码分享

时间:2022-09-19 21:09:32

一,效果图。

iOS实现左右可滑动的选择条实例代码分享

二,工程图。

iOS实现左右可滑动的选择条实例代码分享

三,代码。

rootviewcontroller.h

?
1
2
3
#import <uikit/uikit.h>
@interface rootviewcontroller : uiviewcontroller
@end

rootviewcontroller.m

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "rootviewcontroller.h"
//引入头文件
#import "svsegmentedcontrol.h"
@interface rootviewcontroller ()
@end
@implementation rootviewcontroller
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil
{
  self = [super initwithnibname:nibnameornil bundle:nibbundleornil];
  if (self) {
    // custom initialization
  }
  return self;
}
- (void)viewdidload
{
  [super viewdidload];
  // do any additional setup after loading the view.
  //初始化背景图
  [self initbackgroundview];
}
#pragma -makr -funcitons
-(void)initbackgroundview
{
  svsegmentedcontrol *options = [[svsegmentedcontrol alloc] initwithsectiontitles:[nsarray arraywithobjects:@"购车应用",@"车主应用", nil]];
  options.center=cgpointmake(160, 100);
  [options setselectedsegmentindex:0 animated:no];
  [options addtarget:self action:@selector(segmentedcontrolchangedvalue:) forcontrolevents:uicontroleventvaluechanged];
  [self.view addsubview:options];
}
#pragma -mark -doclickaction
- (void)segmentedcontrolchangedvalue:(svsegmentedcontrol*)segmentedcontrol {
  nslog(@"--index--%i-", segmentedcontrol.selectedsegmentindex);
}
- (void)didreceivememorywarning
{
  [super didreceivememorywarning];
  // dispose of any resources that can be recreated.
}

以上所述是小编给大家介绍的ios实现左右可滑动的选择条实例代码分享,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://www.cnblogs.com/yang-guang-girl/archive/2017/03/28/6631591.html