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];
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];
相关文章推荐
- use code to add Navigation----iphone
- Use the Stack mehod and a temporary Stack to retrieve entries from the Stack source and add
- jooq使用自定义策略生成代码(How to use a custom strategy with the jOOQ code-generator and Maven?)
- [Drupal] How to add the js file and js code block in Drupal
- use code to generate Silverlight Controls at run time, and serialize the control into XAML file
- How to Configure iOS for iPhone and iPad to Use So
- [JavaScript] Use `+` opertor to add one string and one number
- [Angular] Use Angular’s @HostBinding and :host(...) to add styling to the component itself
- Gridview之RowCommand,ButtonField[add buttons and use the RowCommand event to add custom functionality to the control]
- Java Thread Local – How to use and code sample
- [React] Use React.cloneElement to Modify and Add Additional Properties to React Children
- Java ThreadLocal - How to use and code sample
- [Resolved] TF254006: No usable accounts are present in your configuration database. Use TfsConfig accounts /add to add an account and return to this wizard.
- Java ThreadLocal - How to use and code sample
- The robot API &&How to add and use sensor.
- Java ThreadLocal - How to use and code sample
- iphone dev 入门实例6:How To Use UIScrollView to Scroll and Zoom and Page
- use MyButton is simple,only add two file and then add some code just bellow in any dlg src declear the button control and will ok!
- How to use gcov to get code coverage from static library in iphone?
- java - How to install and use db4o for Android? - Stack Overflow