iOS实现左右可滑动的选择条实例代码分享
程序员文章站
2023-12-20 12:50:04
一,效果图。
二,工程图。
三,代码。
rootviewcontroller.h
#import ...
一,效果图。
二,工程图。
三,代码。
rootviewcontroller.h
#import <uikit/uikit.h> @interface rootviewcontroller : uiviewcontroller @end
rootviewcontroller.m
#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实现左右可滑动的选择条实例代码分享,希望对大家有所帮助