UISlider和UIScreenEdgePanGestureRecognizer和简单运用,包括滑动时颜色变化,滑动按钮以及Slider按钮颜色设置

白禄
2023-12-01
#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (void)dealloc
{
    [super dealloc];
}
- (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.
    
    UISlider * slider = [[UISlider alloc] initWithFrame:CGRectMake(80, 50, 160, 20)];
    slider.minimumValue = 0;
    slider.maximumValue = 3.0;
    slider.minimumTrackTintColor = [UIColor redColor];
    slider.maximumTrackTintColor = [UIColor blackColor];
    [slider setThumbImage:[UIImage imageNamed:@"3.png"] forState:UIControlStateNormal];
    
    [self.view addSubview:slider];
    [slider release];
    
    NSArray * arr = [NSArray arrayWithObjects:@"朱江",@"猪点点",@"赵卓尔",@"赵笨笨",@"雨点儿", nil];
    
    UISegmentedControl * seg = [[UISegmentedControl alloc] initWithItems:arr];
    [seg setFrame:CGRectMake(0, self.view.frame.size.height - 40, 320, 40)];
    
//    [self.view removeGestureRecognizer:(UIGestureRecognizer *)seg];
    
    
    seg.tintColor = [UIColor magentaColor];
//    seg.backgroundColor = [UIColor greenColor];
//    seg.alpha = 0.5;
    
    [self.view addSubview:seg];
    [seg release];
    
    
    UIScreenEdgePanGestureRecognizer * screen = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenAction:)];
    [screen setEdges:UIRectEdgeLeft];
    [self.view addGestureRecognizer:screen];
    [screen release];
    
}
- (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
{
    [self.view removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer];
}
- (void)screenAction:(UIScreenEdgePanGestureRecognizer *)screen
{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(20, 50, 280, 380)];
    view.backgroundColor = [UIColor blueColor];
    [self.view addSubview:view];
    [view release];
}
 
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
@end
 类似资料: