你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS學習筆記 (4)

IOS學習筆記 (4)

編輯:IOS開發綜合
使用UISlider實現指定范圍選擇 創建一個滑動條並且把它放在試圖控制器的視圖中。 @interface SliderView:UIViewController @property(non atomic,strong)UISlider *mySlider; @end @synthesize mySlider; -(void)viewDidLoad{     [super viewDidLoad];     self.view.backgroundColor = [UIColor whiteColor];     self.mySlider = [ [UISlider alloc] initWithFrame:CGRectMake(0.0f,0.0f,200.0f,23.0f)];     self.mySlider.center = self.view.center;     self.mySlider.minimumValue = 0.0f;//選擇范圍的最小值     self.mySlider.maximumValue= 100.0f;//選擇范圍的最大值     self.mySlider.value = self.mySlider.maximumValue / 2.0;//當前值     self.mySlider.continuous = NO;//默認YES,若為YES,thumb滑動時會連續調用slider d target。     [self.mySlider addTarget:self action:@selecter(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];     [self.view addSubView:self.mySlider]; } slider上的小滑塊叫做thumb; target -(void)sliderValueChanged:(UISlider *)paramSender{     if([paramSender isEqual:self.mySlider]){         NSLog(@"%@",paramSender.value);     } } slider 的 thumb 圖片選中設置 setThumbImage:forState:方法 UIControlStateNormal  //正常狀態下的thumb ,即沒有點擊的。 UIControlStateHighlighted //選中狀態的thumb,即用戶點擊thumb時顯示的圖片 [self.mySlider setThumbImage:[UIImage imaged:@"ThumbNormal.png"] forState:UIControlStateNormal]; [self.mySlider setThumbImage:[UIImage imaged:@"ThumbHighlighted.png"] forState:UIControlStateHighlighted];   UISegmentedControl 做簡單選項分組 @interface SegmentedControl :UIViewController @property(non atomic,strong)UISegmentedControl *mySegmentedControl; @end; @synthesize mySegmentedControl; -(void)viewDidLoad{     [super viewDidLoad];     self.view.backgrounderColor = [UIColor whiteColor];     NSArray *segments = [[NSArray alloc] initWithObjects:@"iPhone",@"iPad",nil];     self.mySegmentedControl = [[UISegmentedControl alloc]initWithItems:segments];     self.mySegmentedControl.center = self.view.center;     [self.view addSubview:self.mySegmentedControl]; }
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved