iphone 简单控件的使用

from:http://blog.csdn.net/xqls_xqls/article/details/6120896

UILabel  UITextField  UIButton   UISlider 的简单使用。。

 

1. UILabel的使用

 

    UILabel * label1 = [[UILabel alloc] initWithFrame:CGRectMake(21, 8, 120, 30)];
    label1.text = @"Simple Label Simple Label";
    label1.textColor = [UIColor blueColor];
    label1.textAlignment = UITextAlignmentLeft;
    label1.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:10] size:20];
    label1.adjustsFontSizeToFitWidth = YES;
    label1.numberOfLines = 0;
    label1.tag = 0;
    label1.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    [self.view addSubview:label1];
    [label1 release];
    
    UILabel * label2 = [[UILabel alloc] initWithFrame:CGRectMake(21, 60, 280, 50)];
    label2.text = @"文字阴影效果";
    label2.textColor = [UIColor colorWithRed:0.4 green:0.6 blue:0.1 alpha:1.0];
    label2.textAlignment = UITextAlignmentCenter;
    label2.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:2] size:35];
    label2.adjustsFontSizeToFitWidth = YES;
    label2.numberOfLines = 0;
    label2.tag = 0;
    label2.backgroundColor = [UIColor cyanColor];
    label2.shadowColor = [UIColor yellowColor];
    label2.shadowOffset = CGSizeMake(2, 2);
    [self.view addSubview:label2];
    [label2 release];

 

2. UITextField的使用

 

    UITextField * textfield1 = [[UITextField alloc] initWithFrame:CGRectMake(20, 8, 250, 40)];
    textfield1.delegate = self;
    textfield1.text = @"";
    textfield1.placeholder = @"please input text";
    textfield1.textAlignment = UITextAlignmentLeft;
    textfield1.textColor = [UIColor blueColor];
    textfield1.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:0] size:17];
    textfield1.adjustsFontSizeToFitWidth = YES;
    textfield1.borderStyle = 3;
    textfield1.clearsOnBeginEditing = YES;
    //textfield1.clearButtonMode = 3;
    //textfield1.autocapitalizationType = 2;
    //textfield1.keyboardType =5;
    //textfield1.secureTextEntry = YES;
    textfield1.tag = 0;
    textfield1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:textfield1];
    [textfield1 release];

 

3. UIButton的使用

 

    UIButton * button1 = [UIButton buttonWithType:2];
    button1.frame = CGRectMake(20, 20, 30, 30);
    button1.tag = 0;
    button1.backgroundColor = [UIColor grayColor];
    [self.view addSubview:button1];
    
    UIButton *button2 = [UIButton buttonWithType:0];
    button2.frame = CGRectMake(20, 60, 100, 40);
    button2.tag = 0;
    [button2 setTitle:@"button" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    button2.adjustsImageWhenDisabled = NO;
    button2.adjustsImageWhenHighlighted = NO;
    button2.backgroundColor = [UIColor cyanColor];
    [button2 addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];

 

4. UISlider的使用

 

    UISlider *Slider1=[[UISlider alloc] initWithFrame:CGRectMake(25,46,239,23)];
    Slider1.maximumValue=100;
    Slider1.minimumValue=0;
    Slider1.value=50;
    Slider1.continuous=NO;
    Slider1.tag=0;
    Slider1.backgroundColor=[UIColor whiteColor];
    [Slider1 addTarget:self action:@selector(valueChangeTest) forControlEvents:UIControlEventValueChanged];
    self.slider = Slider1;
    [self.view addSubview:slider];
    [Slider1 release];


1。 UIActivityIndicatorView的使用

 

    UIActivityIndicatorView *Activity1=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:0];
    Activity1.frame=CGRectMake(100,100,40,40);
    Activity1.hidesWhenStopped=NO;
    [Activity1 startAnimating];
    Activity1.tag=0;
    Activity1.backgroundColor=[UIColor colorWithRed:0.000000 green:0.000000 blue:0.000000 alpha:1.000000];
    [self.view addSubview:Activity1];
    [Activity1 release];
    
    UIActivityIndicatorView *Activity2=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:0];
    Activity2.frame=CGRectMake(160,100,40,40);
    Activity2.hidesWhenStopped=NO;
    [Activity2 stopAnimating];
    Activity2.tag=0;
    Activity2.backgroundColor=[UIColor colorWithRed:0.000000 green:0.000000 blue:0.000000 alpha:1.000000];
    [self.view addSubview:Activity2];
    [Activity2 release];

 

2。UISegmentedControl的使用

 

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    lable = [[UILabel alloc] initWithFrame:CGRectMake(80, 100, 160, 30)];
    lable.text = @"color is not Selected!!";
    lable.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:0] size:17];
    lable.backgroundColor = [UIColor whiteColor];
    lable.numberOfLines = 2;
    [self.view addSubview:lable];
    
    NSMutableArray *seg1Items = [[NSMutableArray alloc] init];
    [seg1Items addObject:@"red"];
    [seg1Items addObject:@"green"];
    [seg1Items addObject:@"blue"];
    //[seg1Items addObject:[UIImage imageNamed:@"PicName.jpg"];
    UISegmentedControl *Seg1 = [[UISegmentedControl alloc] initWithItems:seg1Items];
    [seg1Items release];
    Seg1.frame = CGRectMake(20, 300, 280, 30);
    Seg1.tintColor = [UIColor orangeColor];
    [Seg1 setWidth:70 forSegmentAtIndex:1];
    Seg1.segmentedControlStyle = 0;
    //Seg1.backgroundColor = [UIColor whiteColor];
    Seg1.momentary = YES;
    Seg1.selectedSegmentIndex = UISegmentedControlNoSegment;
    Seg1.tag = 0;
    [Seg1 addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:Seg1];
}

- (void)segmentAction:(id)sender
{
    switch ([(UISegmentedControl*)sender selectedSegmentIndex]) {
        case 0:
            lable.textColor = [UIColor redColor];
            lable.text = @"red selected!!";
            break;
        case 1:
            lable.textColor = [UIColor greenColor];
            lable.text = @"green selected!!";
            break;
        case 2:
            lable.textColor = [UIColor blueColor];
            lable.text = @"blue selected!!";
            break;
        default:
            NSLog(@"color is not Selected!!");
            break;
    }
}

 

3。 UISwitch的使用

 

    UISwitch *Switch=[[UISwitch alloc] initWithFrame:CGRectMake(101,20,94,27)];
    Switch.on=NO;
    Switch.tag=0;
    Switch.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:Switch];
    [Switch release];

 

4。 UIPageControl的使用

 

    UIPageControl *Page1=[[UIPageControl alloc] initWithFrame:CGRectMake(50,100,200,36)];
    Page1.numberOfPages=10;
    Page1.currentPage=5;
    Page1.tag=0;
    Page1.backgroundColor=[UIColor colorWithRed:0.000000 green:0.000000 blue:0.000000 alpha:1.000000];
    [self.view addSubview:Page1];
    [Page1 release];

 

5。 UIProgressView的使用

 

    progress = 0;
    UIProgressView *Progress1=[[UIProgressView alloc] initWithFrame:CGRectMake(30,200,200,12)];
    Progress1.progressViewStyle=1;
    Progress1.progress=progress * 0.01;
    Progress1.tag=0;
    Progress1.backgroundColor=[UIColor whiteColor];
    self.progressview = Progress1;
    [Progress1 release];
    [self.view addSubview:progressview];
    
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(run) userInfo:nil repeats:YES];

 

- (void)run
{
    progress = progress > 100 ? 0 : progress + 1;
    [progressview setProgress:progress*0.01];
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值