Use code to add UILabel and UIButton----iphone

UILabel *scoreLabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.view.size.width / 2), 0.0, 150.0, 43.0) ];

scoreLabel.textAlignment =  UITextAlignmentCenter;

scoreLabel.textColor = [UIColor whiteColor];

scoreLabel.backgroundColor = [UIColor blackColor];

scoreLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(36.0)];

[self addSubview:scoreLabel];

scoreLabel.text = [NSString stringWithFormat: @"%d", score];


 

UIButton *Diary_BTN=[UIButton buttonWithType:UIButtonTypeRoundedRect];

[Diary_BTN setTitle:@"日记" forState:UIControlStateNormal];

Diary_BTN.frame=CGRectMake(30,20,  9060);

Diary_BTN.tag=1;

[Diary_BTN addTarget:self action:@selector(pushView:) forControlEvents:UIControlEventTouchUpInside];

//add the image

NSString *path=[[NSBundle mainBundle]pathForResource:@"diary" ofType:@"png"];

UIImage *image=[UIImage imageWithContentsOfFile:path];

//[Diary_BTN setImage:[UIImage imageNamed:@"diary.png"] forState:UIControlStateNormal];

[Diary_BTN setImage:image forState:UIControlStateNormal];

[self.view addSubview:Diary_BTN];

你可能感兴趣的:(Use code to add UILabel and UIButton----iphone)