(001)UIView

#import "AlinViewController.h"

@interface AlinViewController ()

@end

@implementation AlinViewController

- (void)viewDidLoad
{
[super viewDidLoad];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 60, 60)];
label.text = @"苹果开发";
label.textColor = [UIColor blueColor];

[self.view addSubview:label];

////////////////


UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectZero];
label2.center = CGPointMake(100, 100);
label2.frame = CGRectMake(90, 90, 90, 90);
label2.text = @"测试";
[self.view addSubview:label2];

///////////////
NSLog(@"width = %f",label2.frame.size.width);
NSLog(@"height = %f",label2.frame.size.height);
NSLog(@"x = %f",label2.frame.origin.x);
NSLog(@"y = %f",label2.frame.origin.y);
NSLog(@"centerX = %f",label2.center.x);
NSLog(@"centerY = %f",label2.center.y);

///////////////
//label2.hidden = !label2.hidden;
label2.alpha = 0.5;//设置透明度
//[label2.backgroundColor colorWithAlphaComponent:0.5];???

//////////////////////
UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectZero];
label3.frame = CGRectMake(0, 200, 90, 90);
label3.text = @"测试*************************";
[label3 sizeToFit];
[self.view addSubview:label3];

///////////////////////
MyLabel *myLabel = [[MyLabel alloc] initWithFrame:CGRectZero];
myLabel.text = @"自定义标签";
[myLabel sizeToFit];
[self.view addSubview:myLabel];

//////////////////////
UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectZero];
label4.frame = CGRectMake(0, 300, 300, 90);
label4.text = @"main";
[self.view addSubview:label4];

UILabel *label5 = [[UILabel alloc] initWithFrame:CGRectZero];
label5.frame = CGRectMake(0, 0, 30, 30);
label5.text = @"sub";
[label4 addSubview:label5];

UILabel *label6 = [[UILabel alloc] initWithFrame:CGRectZero];
label6.frame = CGRectMake(60, 30, 50, 30);
label6.text = @"sub2";
label6.tag = 333;
[label4 addSubview:label6];

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0, 400, 25, 25);
[button setTitle:@"tag" forState:UIControlStateNormal];
[button sizeToFit];
[button addTarget:self action:@selector(searchTag) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}

-(void)searchTag
{
UILabel *label = (UILabel*)[self.view viewWithTag:333];
NSLog(@"label.text = %@",label.text);
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

@end

 

posted @ 2013-08-07 09:21  雪中飞雁  阅读(84)  评论(0)    收藏  举报