您的位置:首页 > 产品设计 > UI/UE

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

2011-09-01 15:33 302 查看
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, 90, 60);

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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐