当前位置:编程学习 > wap >>

IOS学习笔记 (4)

使用UISlider实现指定范围选择
创建一个滑动条并且把它放在试图控制器的视图中。
@inte易做图ce 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 做简单选项分组
@inte易做图ce 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];
}
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,