IOS基本控件使用

来源:互联网 发布:讲不出再见知乎 编辑:程序博客网 时间:2024/04/29 03:15

UIImageView

    UIImageView *sport = [[UIImageView alloc]initWithFrame:CGRectMake(30, 202, 66, 68)];
    sport.image = [UIImage imageNamed:@"cardSport.png"];
    sport.userInteractionEnabled=YES;
    UITapGestureRecognizer *singleTap1 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage1)];
    [sport addGestureRecognizer:singleTap1];
    [singleTap1 release];


UILabel

    UILabel * name = [[UILabel alloc]initWithFrame:CGRectMake(89, 104, 143, 46)];
//    name.text = @" ";
//    name.backgroundColor = [UIColor clearColor];
    name.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"Matching Game.png"]];



UIButton

    UIButton * setting =[[UIButton alloc]init];
//    UIButton *setting = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    setting.frame = CGRectMake(224, 382, 73, 44);
    setting.titleLabel.textColor= [UIColor blackColor];
    [setting setTitle:@" " forState:UIControlStateNormal];
    [setting addTarget:self action:@selector(gotosettinggame:) forControlEvents:UIControlEventTouchUpInside];
    setting.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"setting.png"]];



UISwitch

    UISwitch *switch1 = [[UISwitch alloc]initWithFrame:CGRectMake(212, 268, 79, 27)];
    UISwitch *switch2 = [[UISwitch alloc]initWithFrame:CGRectMake(212, 349, 79, 27)];
//    [switch1 setOn:YES];
    [switch1 setOn:voiceon];
    
    
    [switch1 addTarget:self action:@selector(switchAction1:) forControlEvents:UIControlEventValueChanged];
//    [switch2 setOn:YES];
    [switch2 setOn:soundon];
    
    [switch2 addTarget:self action:@selector(switchAction2:) forControlEvents:UIControlEventValueChanged];


UISegmentedControl

    NSArray *array=@[@"easy",@"middle",@"difficult"];
    UISegmentedControl *segcontro=[[UISegmentedControl alloc]initWithItems:array];
    segcontro.segmentedControlStyle=UISegmentedControlStyleBordered;
    //设置位置 大小
    segcontro.frame=CGRectMake(54, 179, 235, 44);
    //默认选择
    segcontro.selectedSegmentIndex=1;
    
    //设置背景色
    segcontro.tintColor=[UIColor greenColor];
    //设置监听事件
    [segcontro addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];




UIProgressView

@property (nonatomic,retain)UIProgressView *powerBar;

powerBar=[[UIProgressView alloc]initWithFrame:CGRectMake(80, 20, 150, 9)];

    //powerBar.progress = 1.0*(1/60)*gametime;
    NSString *stringFloat = [NSString stringWithFormat:@"%f",100-1.0*1/60*gametime*100];
    [powerBar setProgress:1.0*1/60*gametime];





0 0
原创粉丝点击